Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Selecting From Multiple Tables With Cactivedataprovider

$
0
0
I have 3 tables:
Topics, Users and Details
(those are some of the tables of a custom forum)

Topics contains (among other usual fields) the id (FK) of the user that created the topic. Users contains nick/pass and id (PK) Details contains (among other usual fields) the id (FK) of the user.

Relations: One user can have one 1 detail. One user can have multiple topics, but a topic can be created only by one user.

Topic relations:

return array(
'user' => array(self::BELONGS_TO, 'User', 'User_iduser'),
);



User relations:

return array(
    'details' => array(self::HAS_ONE, 'Details', 'User_iduser'),
);


I'm trying to get a list with Topics and User details (let's say for example the topic name and the user's name).

Currently I have this:

$dataProvider=new CActiveDataProvider('Topic', array(
    'criteria'=>array(
    'with'=>array('user.details')
    )
));


But as you can imagine, it's not working (read as in it's not selecting anything from the tbles Users or Details).

What's wrong with my code?


+++++++++++++++


This code selects fields from the table user (and the topic table):

Topic::model()->with('user')->findAll();



But this one won't select from details, users and topic:

Topic::model()->with('user.details')->findAll();


Also, I need a
CActiveDataProvider
solution as I need it for zii widgets (means, even if some kind of modification on the
Topic::model()->with()....
code get's to select from the 3 tables it won't be really helpful)

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>