Brian Cain Fri Dec 07 23:40:44 -0500 2012

Subject: Custom 'belongs_to' Association?

I need to setup an association using belongs_to, but the PK & FK fields are not simple "ids".

I have table [customers] w/PK [c_key].
I have table [sessions] w/PK [s_key] and FK [c_id].

I need to set the sessions to "belong to" customers.

Any help?


Brian Cain Sat Dec 08 00:09:59 -0500 2012

Got it!

class Customer extends ActiveRecord\Model
{
    public static $table_name = "customers";
    public static $primary_key = "c_key";

}
class Session extends ActiveRecord\Model
{
    public static $table_name = "sessions";
    public static $primary_key = "s_key";
    static $belongs_to= array(  
                array('customer', 'select' => 'c_key,  username' ,
                       'foreign_key' => 'c_id' 
                )
    ); 
}

Found help here:
http://forum.phpontrax.com/viewtopic.php?p=1851&sid=6ce0319f7ef35c1e2b440d76c90bcb3c

(1-1/1)