Yii Framework Forum: Joining a table from joined results - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Joining a table from joined results All into one query. Rate Topic: -----

#1 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 01 May 2010 - 07:24 AM

Hi @ all !

I'm trying to do a relational query that works fine under PHPmyadmin.
In that query I'm joining "forum posts" to a main table called "forum topics".
Each post has one user_id so I'm wondering if CActiveRecord can do a such query.

As I tested CActiverecord always joins using the main id :
Example :
using foobarTopics::model->findAll(....
I'll obtain :
SELECT `t`.`id` [...] FROM `foobarTopics` `t` LEFT OUTER JOIN `foobar` `postId` ON (`postId`.`topicId`=`t`.`id`)

So I tried some relations like this :
'userId'=>array(forumPosts::HAS_ONE, 'User','id'),


But I always obtain :
ON (`postId`.`topicId`=`t`.`id`)

where I expect :
ON (`postId`.`topicId`=`postId`.`id`)

Any suggestions ?
And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#2 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 01 May 2010 - 07:39 AM

oops, problem solved.
a foreign key was missing
And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users