Retrieve Related Model Data in One-To-Many Relation

What Just Happened?

The first line in the index() action of the AuthorsController sets the model attribute $recursive to 1.

What Just Happened?

The first line in the index() action of the AuthorsController sets the model attribute $recursive to 1.

$this->Author->recursive = 1;

This special attribute is an integer that specifies the number of levels we want our model to fetch associated model data in the next find(‘all’) or find(‘first’) operations. In the AuthorsController, we set it to 1 for the Author model. This means the subsequent Author->find(‘all’) operation will return all associated model data that are related directly to the Author model. The result of the function call Author->findAll() is then stored in a variable $authors. The returned result is an array containing all authors and their book information.

Source: http://www.packtpub.com/article/working-with-simple-associations-using-cakephp

Leave a Reply

Your email address will not be published. Required fields are marked *