user3048231
user3048231

Reputation: 75

CDbCriteria returning only one tables data not from joined ones

I am using yii and CDbCriteria to fetch results from 3 tables using join. Here is what i have done till now:

$criteria->select = 't.product_id, t.title, t1.title, t2.filename,';
$criteria->join = 'INNER  JOIN shop_category as t1 ON t1.category_id = t.category_id';
$criteria->join .= ' INNER  JOIN shop_image as t2 ON t2.product_id = t.product_id';

but it is only giving me t.product_id and t.title and not other two. When i ran this query on phpMyAdmin it gave all results perfectly! What am i doing wrong?

Upvotes: 1

Views: 437

Answers (1)

Developerium
Developerium

Reputation: 7265

if you use criteria with active record, the data populated is in bounds of models properties and attributes,

but you can have other columns as properties of the model,

lest suppose you have productTitle and productFilename in your model:

$criteria->select = 't.product_id, t.title, t1.title as productTitle, t2.filename as productFilename';

Upvotes: 1

Related Questions