请教“自我MANY_MANY关联的model”的问题

想知道用AR的relation功能如何描述像twitter那样的i follow 和 following me的表自关联关系

有一张UserFriend表(userId,friendId)来记录关联数据

我在User model的relations里是这样写的:

‘iFollow’=>array(self::MANY_MANY,‘User’,‘UserFriend(UserId,FriendId)’),

‘followMe’=>array(self::MANY_MANY,‘User’,‘UserFriend(FriendId,UserId)’),

在controller里面测试了一下,代码如下:

$iFollow=User::model()->with(‘iFollow’)->findAll();

var_dump($iFollow);

提示了Fatal错误:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77 bytes) in /var/www/yii-1.0.8.r1317/framework/db/CDbCommand.php on line 308

不知道问题出在哪里,能否请qiang哥指点一下,非常感谢 :)

内存泄漏,是不是在user里互相引用对象了?

好友关系,就是user与user自身的many_many关联

不知道哪里写错了

问题已解决,打扰各位了。

错误是因为测试输出的时候,没有设定好查询条件,改成下面的即可

$criteria=new CDbCriteria;

$criteria->condition=‘User.id=’.Yii::app()->user->id;

$iFollow=User::model()->with(‘iFollow’)->find($criteria);

$followMe=User::model()->with(‘followMe’)->find($criteria);

echo(‘i follow:<br />’);

foreach($iFollow->iFollow as $one)

{

echo(&#036;one-&gt;username.'&lt;br /&gt;');	

}

echo(‘follow me:<br />’);

foreach($followMe->followMe as $one)

{

echo(&#036;one-&gt;username.'&lt;br /&gt;');	

}