protected function execute(InputInterface $input, OutputInterface $output) { $bookId = $input->getArgument(AddBookAuthorCommand::BOOK_ID); $authorId = $input->getArgument(AddBookAuthorCommand::AUTHOR_ID); $book = $this->getBookIfExists($output, $bookId); $author = $this->getAuthorIfExists($output, $authorId); $oldBookAuthor = BookAuthorQuery::create()->findPk(array($bookId, $authorId)); if ($oldBookAuthor == NULL) { $output->writeln("Book " . $bookId . " - author " . $authorId . "association already exists."); return; } $bookAuthor = new BookAuthor(); $bookAuthor->setAuthor($author); $bookAuthor->setBook($book); $bookAuthor->save(); $output->writeln("Book " . $bookId . " - author " . $authorId . "association successfully added."); }
public function addAuthor($author) { $bookauthor = new BookAuthor(); $author->save(); $bookauthor->book_id = $this->id; $bookauthor->author_id = $author->id; $bookauthor->save(); }
protected function saveAssociation($model, $author) { // record book/author association $ba = new BookAuthor(); $ba->book_id = $model->id; $ba->author_id = $author->id; $ba->save(); }