我已经设置了一个多态关联,它是这样的:
Media has a 1-to-1 association with either Photo, Video or Text
Media模型的摘录如下:
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'],
内的照片子模型,使它不会查询所有的子模型,而不是每次查看类型,然后选择正确的子模型?
穿着同样的鞋子。您可以添加如下条件:
'conditions' => ['LfrMomentArticle.type' => 'photo'],
如果你有一个类型字段在你的LfrMomentArticle模型(当然在数据库)