Question

I'm fairly new to Yii and have run into a barrier with related models. I suspect other beginners also run into this from time to time and would be grateful for any input even if just to point me in the right direction as I can't find anything on this problem.

I have three related models-

  • Posts
  • Responses
  • Comments

Posts Have_Many Responses and Responses Have_Many Comments-

Post->Repsonse->Comment

I want to run a query in the Post controller, for a particular Post that returns associated Responses with their associated Comments. I am under the impression (rightly/wrongly) that this can be done using a find method in conjunction with, some variation of the following-

Post::model()->with('responses','comments')->findAll();

Obviously this wouldn't work. Does anybody know of a method or approach to solve this problem?

Was it helpful?

Solution

Yii do it in very better way what you are looking. I hope this will sole your problem.

Post::model()->with('responses','responses.comments')->findAll();

But one thing their should be relation comments in response model to comments model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top