0
votes

I have a polymorphic association that I have set up it goes like this:

Media has a 1-to-1 association with either Photo, Video or Text

an excerpt of the Media model looks like this:

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' => ''
    ),

Is there a way to specify a condition like

'conditions' => ['LfrMomentArticle.type' => 'photo'],

inside the Photo submodel so that it will not query over all the submodels each time but instead look at the type and then pick the correct submodel?

1
The answer is seemingly in the question. Have you tried anything? - AD7six

1 Answers

0
votes

walking in the same shoes. you can add the condition like:

'conditions' => ['LfrMomentArticle.type' => 'photo'],

if you have a type field in your LfrMomentArticle model(and of course in the db).