我有一个多态关联,我设置它是这样的:
Media has a 1-to-1 association with either Photo, Video or Text
媒体模型的摘录如下所示:
public $hasOne = array(
'Photo' => array(
'className' => 'Photo',
'foreignKey' => 'media_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Text' => array(
'className' => 'Text',
'foreignKey' => 'media_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
有没有办法指定像
这样的条件'conditions' => ['LfrMomentArticle.type' => 'photo'],
在Photo子模型中,以便每次都不会查询所有子模型,而是查看类型,然后选择正确的子模型?
答案 0 :(得分:0)
'conditions' => ['LfrMomentArticle.type' => 'photo'],
如果您的LfrMomentArticle模型中有一个类型字段(当然还有数据库中)。