0
votes

I have 5 tables:

  1. Form -> (fields : id , name) HasMany (Form)

  2. Field -> (fields : id , type , name , form_id) HasMany (Fvarchar,Ftext,Ftinyint) BelongsTo (Form)

  3. Fvarchar -> (fields : id , value , field_id) BelongsTo (Field)

  4. Ftext -> (fields : id , value , field_id) BelongsTo (Field)

  5. Ftinyint -> (fields : id , value , field_id) BelongsTo (Field)

I want find forms with Field[name]->Fvarchar,Ftext,Ftinyint[value] but now when I try to find forms, I have result like this:

$this->Form->find('all',array('contain' => array('Field'=>array('Fvarchar','Ftext','Ftinyint'))

'Form' => array(
            'id' => '1',
            'name' => 'mobile',
            'Field' => array(
                (int) 0 => array(
                    'name' => 'bluetooth',
                    'type' => 'Ftinyint',
                    'id' => '1',
                    'form_id' => '1',
                    'Ftext' => array(),
                    'Fvarchar' => array(),
                    'Ftinyint' => array(
                        (int) 0 => array(
                            'value' => true,
                            'id' => '2',
                            'field_id' => '1'
                        )
                    )
                ),

but I want to filter tables(Ftext,Fvarchar,Ftinyint) with Field[type] :

'Form' => array(
            'id' => '1',
            'name' => 'mobile',
            'Field' => array(
                (int) 0 => array(
                    'name' => 'bluetooth',
                    'type' => 'Ftinyint',
                    'id' => '1',
                    'form_id' => '1',
                    'Ftinyint' => array(
                        (int) 0 => array(
                            'value' => true,
                            'id' => '2',
                            'field_id' => '1'
                        )
                    )
                ),

thanks

1
I tried reading your question twice, but just couldn't follow. If there's any way you can simplify the question, I think you'll have better luck getting answered. Strip out anything that's irrelevant, make table names not things that are already in use like "int", "tinyint", "field"...etc. (normally i wouldn't recommend posting fake table names, but - in this case I think it will help ease of understanding. - Dave
thanks , i want to filter (dont use) Tables that have no value in it from result and query - ali786

1 Answers

0
votes

I am struggling to understand what your question is (sorry, I can see that English isn't your first language) but I am interpreting it as meaning that you want to contain the Field model, where the type is one of those three you have specified?

Does this help?

$this->Form->find('all',array(
    'contain' => 'Field',
    'conditions' => array(
        'Field.type' => array(
            'OR' => array('Fvarchar', 'Ftext', 'Ftinyint')
        )
    )
));

Untested, of course. But something like that.