只是一个我无法找到答案的快速问题:
CakePHP中的find方法不起作用,这是正常的吗?:
$this->Video->Client->find('all', array(
'fields' => array('Video.video_id'),
'conditions' => array('Client.client_id' => 1)
))
在这样的数据库结构中:
视频模型:
class Video extends AppModel {
public $name = 'Video';
public $primaryKey = 'video_id';
public $hasAndBelongsToMany = array(
'Client' => array(
'className' => 'Client',
'joinTable' => 'clients_videos',
'foreignKey' => 'video_id',
'associationForeignKey' => 'client_id',
'unique' => 'keepExisting'
)
);
}
客户端型号:
class Client extends AppModel {
public $name = 'Client';
public $primaryKey = 'client_id';
public $hasAndBelongsToMany = array(
'Video' => array(
'className' => 'Video',
'joinTable' => 'clients_videos',
'foreignKey' => 'client_id',
'associationForeignKey' => 'video_id',
'unique' => 'keepExisting'
)
);
public $belongsTo = array(
'User'
);
}
编辑1 :
将client_id
改为id
,就像CakePHP的约定一样。
现在我在$this->Video->find('all')
上返回的内容:
array(
(int) 0 => array(
'Video' => array(
'id' => '5',
'video' => '/files/cz/Chrysanthemum.jpg'
),
'Client' => array(
(int) 0 => array(
'id' => '5',
'name' => 'CZ',
'image' => null,
'vector_image' => null,
'slug' => 'cz',
'user_id' => '1'
)
)
),
)