访问有很多

问题描述

| 嗨,我是我第一次涉足CakePHP的Rails程序员,但似乎遇到了一些麻烦: 我有以下关系:
BookStore has_many Books
Book belongs_to BookStore
Book has_and_belongs_to_many Authors
Author has_and_belongs_to_many Books
如果我有一个BookStore实例,如何获得该BookStore的作者列表,以便可以在其视图中进行迭代? 提前谢谢了, 灰     

解决方法

只要在模型中正确设置了关系,CakePHP将为您完成大部分工作。可以在http://book.cakephp.org/view/1000/Models中找到有关此操作的良好指南。
$authors = $this->Author->find(\'all\',array(
    \'conditions\' => array(
        \'Bookstore.id\' => $id,),));

$this->set(\'authors\',$authors);