Eager load problem

Hi all,

I’ve just started using Yii 1.1 after my successfully finished Yii 1.0 based project.

My problem is that the eager load doesn’t work for me with yii 1.1 I’ve just started developing my new site, so I used everything generated by yiic.

I’ve got 2 tables:

TBUser

		'userId' => 'User',


		'name' => 'Name',

UserLogin

		'TBUser_userId' => 'Tbuser User',


		'perms' => 'Perms',

there is 1:1 relation between tables

TBUser model has this:

		'userLogin' => array(self::HAS_ONE, 'UserLogin', 'TBUser_userId'),

UserLogin model:

		'tBUser_user' => array(self::BELONGS_TO, 'TBUser', 'TBUser_userId'),

I’d like to get one row from both joined table, so I used this in UserIdentity.php at line 23:

23: $user = TBUser::model()->with(‘userLogin’)->find(“name LIKE BINARY '” . $this->username . “’”);

And I got this fatal error:

Invalid argument supplied for foreach()

Invalid argument supplied for foreach()

(/mnt/linmedia/www/yii1.1/framework/db/ar/CActiveFinder.php:727)

Stack trace:

#0 /mnt/linmedia/www/yii1.1/framework/db/ar/CActiveFinder.php(396):

CJoinElement->runQuery()

#1 /mnt/linmedia/www/yii1.1/framework/db/ar/CActiveFinder.php(73):

CJoinElement->find()

#2 /mnt/linmedia/www/yii1.1/framework/db/ar/CActiveFinder.php(91):

CActiveFinder->query()

#3 /mnt/linmedia/www/t4/protected/components/UserIdentity.php(23):

So what’s wrong with that query?

One additional info. The Yii generated query is fine:

SELECT t.userId AS t0_c0, t.name AS t0_c1, userLogin.TBUser_userId AS t1_c0, userLogin.passwd AS t1_c1, userLogin.salt AS t1_c2, userLogin.perms AS t1_c3, userLogin.active AS t1_c4, userLogin.creationTime AS t1_c5, userLogin.lastVisitedTime AS t1_c6 FROM TBUser t LEFT OUTER JOIN UserLogin userLogin ON (userLogin.TBUser_userId=t.userId) WHERE (name LIKE BINARY ‘myusername’)

Here is the solution:

http://www.yiiframework.com/forum/index.php?/topic/6403-how-to-use-cjoinelement-on-a-table-without-primarykey-in-database/page__hl___pkAlias__fromsearch__1

The primary key was missing from the table, and Yii 1.1 doesn’t support that :)