0

I'm using simple table inheritance with Laravel (using a plugin like Nanigans/single-table-inheritance or intrip/laravel-single-table-inheritance but I can also implement my own one, that isn't the problem).

I'm also using belongsToMany relations: A book can has many words and a word can be in many books.

Imagine that I have something like:

Book {
  verbs() { belongsToMany ('Verb',...) }
  adjectives() { belongsToMany ('Adjective',...) }
}

And also image that 'verb' and 'adjective' are sharing the table 'words' with different 'type' field and extending a model 'Word'.

The problem is when I'm using sync() (like $book->verbs()->sync([1,2,3])) is also clearing the adjectives relations when it shouldn't.

Do you know any solution?

kanashin
  • 365
  • 1
  • 3
  • 14

1 Answers1

0

I would select all the Verbs of the book. Detach them from it and attach the new Verbs comings from the Input form :)

splig
  • 125
  • 7
  • Thank you for your comment. I have though that too, but I was looking for an other "elegant" solution. Anyway if I cannot find anything I will take this way. – kanashin Mar 23 '15 at 17:39