ok.. shame on me.. it works with: $author_tutorial = new AuthorTutorial(); $author_tutorial->author_id = $author->getId(); $author_tutorial->tutorial_id = $tutorial->getId(); $author_tutorial->save();
But how do I check for duplicates - if the $author is already linked with the tutorial? Do I need to do a SELECT manually or is their some function like: $tutorial->hasAuthor($author)? On 30 Apr., 23:40, comb <sa...@gmx.net> wrote: > Hi! > > I have a tutorial and author model in a many-to-many relation > (AuthorTutorial). > Now I want to add a author to a concrete tutorial which already has > authors, without duplicates. > How do I do that? > > I tried s/th like this: > // temporarily save old authors: > $authors = $tutorial->getAuthors(); > // remove all authors: > $tutorial->AuthorTutorial->delete(); > // add author: > $authors[] = $current_author; > // add all authors again: > $trick->setAuthors($authors); > > But this ends up in a "SQLSTATE[23000]: Integrity constraint > violation: 1048 Column 'author_id' cannot be null"-Error. :-( > If I use $authors[] = $current_author->getId(); instead i get a "Fatal > error: Call to a member function save() on a non-object" > > Any help will be appreciated > comb > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/symfony-users?hl=en -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en