CActiveDataProvider doesn't return all the fields

I have a method in an ActiveRecord data model

$criteria = new CDbCriteria;

$criteria->join = ‘JOIN bounce.tracking_clicks AS tc ON t.click_id = tc.click_id JOIN bounce.tracking ON tracking.tracking_id = tc.tracking_id’;

$criteria->condition = “$date >= ‘{$from}’ AND $date < ‘{$to}’”;

return new CActiveDataProvider(get_class($this), array(

	'criteria'=&gt;&#036;criteria,	)); 

the problem is when I pass this to gridview, all the fields are from this table, I want all the fields from other two tables. they are not here.

I checked weblog, the query is like this:

Querying SQL: SELECT COUNT(*) FROM ThreadSaleTracker t JOIN

bounce.tracking_clicks AS tc ON t.click_id = tc.click_id

					   JOIN bounce.tracking  ON tracking.tracking_id = tc.tracking_id

WHERE (trans_post_date >= ‘2010-06-02’ AND trans_post_date < '2010-06-02

23:59:59’) AND (adtrack_source = ‘google’)

It works fine if I run it on mysql command line and everything got returned including other two tables.

Did I miss something, how come the query has everything $data from CActiveDataProvider doesn’t have all fields

Appreciate all helps

You should set the relations in your model.

Then you can access the field of the other tables with $data->tracking_clicks->fieldName.

You can even avoid to write the join statement, and use $criteria->with=array(‘tracking_clicks’,‘tracking_id’);

Well, I did tried relation, it is the same. I watched the weblog in my browser, the query looks fine, however the result doesn’t have the fields from other table. I don’t know if it is a foreign key issue. Since for the first table, the click_id is not a primary key of any table.

I have table A: field1, field1, tracking_id, xxxx

relation: ‘visit’=>array( self::MANY_MANY, ‘C’, B(click_id, tracking_id) )

table B: click_id, tracking_id

table C: tracking_id, ip, time, ***

when I join A, B, C together, the model A doesn’t return all the fields even if I use with. I tried use join in criteria or with, doesn’t work in either way. I did this before in one site last year, it worked fine, don’t know what is going on .

Anyway, I have to work around, So I create a view to join three tables together, then build model class base on the view, everything is fine. However I still want to find out what is going on there, I don’t like work around