O'Reilly logo

Yii Rapid Application Development Hotshot by James R. Hamilton III, Lauren J. O'Meara

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Relationship Therapy

We will make use of the books' many-to-many relationship with authors. We will have to make moderately extensive changes to the model, the controller, and pertinent views. Hang on to your hat!

Engage Thrusters

  1. Update the book model to capture the author relationship (open ch2 | Source Files | protected | models | Book.php):
    'authors' => array(self::MANY_MANY, 'Person',
      'bookauthor(author_id, book_id)', 'index'=>'id'),
      'bookauthors' => array(self::HAS_MANY, 'BookAuthor', 
      'book_id', 'index' => 'author_id'),
  2. Update loadModel() in the book controller to include related author data (open ch2 | Source Files | protected | controllers | BookController.php):
    $model=Book::model()->with("authors")->findByPk($id);
  3. Add an authors display to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required