tags:

views:

5

answers:

0

I'm using RedBean PHP ORM 1.2 with Zend and Mysql for a new project. I'm still in the process of learning it and it works very well for many scenarios, except i cant find how to load beans related by foreign keys. Allow me to explain.

I have two tables; members and feeds. Each 'feed' is linked via a foreign key (in MySQL) to a member. The schema (of sorts) is like this :

Member table:
 ID - Primary Key
 NAME - A text field

Feeds Table:
 ID - Primary Key
 COMMENT - A text field
 USER_ID - This is linked via a MySQL FK to Member.ID

What i would like to do is something like :

 $feed = $rb->load('feeds',1);
 $feed->member->NAME //this should get me the name of the member using the FK

But i cant see how i can do this. I have read about links, associations and trees but none of those work for the scenario where data already exists in the table and i just need to pull a bean and another bean thats related. For clarification, here is the code that does what i want :

$feed = $rb->load('feeds',1);
$member = $rb->load('members',$feed->USER_ID);
$member->NAME //This works

I'd really like to avoid that extra line, and more importantly having to redeclare that FK on the App level.

Your comments and thoughts are welcome.