Active Record Relations ?

Hi, :)

i have tables structure like this:

and i want to get data:

[b]

product.product_id,product.model, product_description.description,category_description.description[/b]

and i have create relation in my activerecord:

product:




public function relations(){

		return array(

			'deskripsi'=>array(self::HAS_MANY,'TProductDescription','product_id'),

		);

	}



ProductDescription




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'product'=>array(self::BELONGS_TO,'TProduct','product_id'),

			'category'=>array(self::MANY_MANY,'TCategory','product_to_category(product_id,category_id)'),

		);

	}



and this code to get data:




$provider = new CActiveDataProvider('TProductDescription',						

	array(

		'criteria'=>array(

			'with'=>array('product','category'),

			'select'=>'*',

			'condition'=>'t.language_id=1',

		)

	)

);



but get error:




The relation "category" in active record class "TProductDescription" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables



this sample for manual:




select 

b.product_id,

b.model,

a.description,

d.description

From product_description as a

left join product as b

on a.product_id = b.product_id

left join product_to_category as c

on b.product_id = c.product_id

left join category_description as d

on c.category_id = d.category_id

WHERE a.language = 1



what is wrong with my code ?

thank you

Hi, any idea ?

hello, anyone ? :)

there may be another way ?

for while I use sql provider

In your SQL code you don’t incorporate any category table (assumed from model TCategory).

Should the relationship look like this? Or, if you intended to use it, is something wrong in the category table?




'category'=>array(self::MANY_MANY,'TCategoryDescription','product_to_category(product_id,category_id)'),



/Tommy