【发布时间】:2015-10-13 03:50:22
【问题描述】:
我已经建立了一个多态关联,它是这样的:
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 子模型中,这样它就不会每次都查询所有子模型,而是查看类型然后选择正确的子模型?
【问题讨论】:
-
答案似乎在问题中。你有没有尝试过?