Search in related table

Hello!

Hello!

I have got a problem with searching in relation table.


Product table (id,name...)

Param table (id,key,value..)

Product has got HAS_MANY relation with Param

and Param has got BELONGS_TO

I have got data like this:


id;name;

1;product1


id;product_id;key;value

1;1;length;10

2;1;height;20

So I want to search:


$criteria = new CDbCriteria;

        $criteria->group = 't.id';

        $criteria->together = true;

        $criteria->with = array("param");

        $criteria->limit = 100;




        $criteria->compare('param.value',"10",true);

        $criteria->compare('param.key',"length",true);

        $criteria->compare('param.value',"20",true);

        $criteria->compare('param.key',"height",true);

But it does not work.

$criteria->addcondtion does not work too…

How do you use $criteria to get data?


$criteria = new CDbCriteria;

        $criteria->group = 't.id';

        $criteria->together = true;

        $criteria->with = array("param");

        $criteria->limit = 100;




        $criteria->compare('param.value',"10",true);

        $criteria->compare('param.key',"length",true);

        $criteria->compare('param.value',"20",true);

        $criteria->compare('param.key',"height",true);


return new CActiveDataProvider('Product', array(

            'criteria'=>$criteria,

            'pagination'=>array(

                'pageSize'=>10,

            ),

            'sort' => array (

                'defaultOrder'=>array(

                    'date_add'=>CSort::SORT_DESC,

                )

            ),

        ));

Compare or AddCondition or AddSearchCondition works once:


 $criteria->compare('param.value',"10",true);

        $criteria->compare('param.key',"length",true);

But I have got a lot of data in param table. That’s a problem.




        $criteria->compare('param.value',"10",true);

        $criteria->compare('param.key',"length",true);

        $criteria->compare('param.value',"20",true);

        $criteria->compare('param.key',"height",true);



what is the meaning of these compares?

You are first comparing param.value to 10 and then to 20, but only a compare will be used.

So, what is the meaning?