CodeIgniter Forums
Associations - phpactiverecord - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Associations - phpactiverecord (/showthread.php?tid=50346)



Associations - phpactiverecord - El Forum - 03-23-2012

[eluser]Unknown[/eluser]
I'm using phpactiverecord with my project. I'm trying to make use of associations and joins.

First, should I setup associations in both directions on the associated models?

Example:

<pre>

class User extends ActiveRecord\Model {

static $has_many = 'auctions';

}

class Auction extends ActiveRecord\Model {

static $belongs_to = 'user';
}

</pre>

Or should I just setup the parent (User) model association?

In querying the user table to bring in a user's auctions, should I do it using association or "join" in phpactiverecord? What's the difference? Is one better than the other?

Also, both User model and Auction model are associated with Item model. I would like to display the item "name" in my listing. Should I try to do that in the association between auction and item or user and item?

Hope I haven't rambled.

Thanks.

Slider