Re: [DataObject] many to many relationship
| From: | Toni M. | Date: | Wed, 23 Mar 2005 11:45:04 +0000 |
| Subject: | Re: [DataObject] many to many relationship | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18267@lists.php.net to get a copy of this message | ||
Hi,
On dc, 2005-03-23 at 09:31 +0800, digit Shine wrote:
> hi,all
> How to use getLinks() or getLink() to fetch data from
> a many to mary relationship?
>
> There are 3 tables: ph_team.ph_team_user and ph_user,
> which user is a member of team.
> Table ph_team_user has 2 fields: team_id and user_id,
> link to ph_team and ph_user respectively.
>
> my code is:
>
> $team->_id->getLinks();
> while($team->_id->fetch()){
> $team->_id->getLinks();
> echo $team->_id->_user_id->username;
> }
What about doing so:
$team_user->team_id = $t; //if it hasn't value previosly
$team_user->find();
while($team_user->fetch()){
$team_user->getLinks();
echo $team_user->_user_id->username;
}
The links.ini file should be diferent:
[ph_team_user]
team_id = ph_team:id
user_id = ph_user:id
I hope this is useful for you, but I'm not a veteran of DO ;)
Toni.
> Manually user getLink() will be easy to do. But it can
> not fetch data into team object, so not good for
> smarty. Despite of getLinks() waste more resource.
>
> Appreciate of any feedback.
>
> bitShine d_sunshine@163.com
>
> _________________________________________________________
> Do You Yahoo!?
> 150万曲MP3疯狂搜,带您闯入音乐殿堂
> http://music.yisou.com/
> 美女明星应有尽有,搜遍美图、艳图和酷图
> http://image.yisou.com
> 1G就是1000兆,雅虎电邮自助扩容!
>
> http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
>