Alfonso Sermonti Wed Feb 09 10:11:20 -0500 2011

Subject: Foreign key conventions

I do like very much this library
Maybe some options could be better explained... :-)
I was looking for foreign keys in associations. There must be obviously a way to let PHP-AR know that if I have a table named customers and another called invoices, the foreign key in invoices table is customer_id
I guess you used the same convention that one used in class names
table: users, class User, etc... (using the singular form)
I'm italian, so I use italian table names. My customers table is called "clienti"
You showed that I can override the convention using $table_name, and it works.
But what about foreign keys? Is it correct if I guess that, by overriding the table name, the foreign key is modified accordingly? This way, the foreign key in "fatture" table (stands for invoices in italian) should be clienti_id...
Is this the automatic way for using foreign keys or should I everytime use the foreign_key option in the association for any non-standard key?
Thanks


Ricardo Casares Fri Sep 16 15:26:11 -0400 2011

Alfonso Sermonti wrote:

I do like very much this library Maybe some options could be better explained... :-) I was looking for foreign keys in associations. There must be obviously a way to let PHP-AR know that if I have a table named customers and another called invoices, the foreign key in invoices table is customer_id I guess you used the same convention that one used in class names table: users, class User, etc... (using the singular form) I'm italian, so I use italian table names. My customers table is called "clienti" You showed that I can override the convention using $table_name, and it works. But what about foreign keys? Is it correct if I guess that, by overriding the table name, the foreign key is modified accordingly? This way, the foreign key in "fatture" table (stands for invoices in italian) should be clienti_id... Is this the automatic way for using foreign keys or should I everytime use the foreign_key option in the association for any non-standard key? Thanks

I'm in the same situation, please some help here :)

Andrew Wayne Sat Sep 17 03:33:35 -0400 2011

Check out the docs on Association http://www.phpactiverecord.org/projects/main/wiki/Associations
Just add 'foreign_key' to your association options

class Fatture
{
    static $belongs_to = array(
        array('clienti', 'foreign_key' => 'clienti_id')
    );
}

(1-2/2)