Reputation: 187
Tables are
buildings (id)
contacts(id)
building_administrators (id, building_id, contact_id)
Model is
Model_Building {
protected $_has_many = array(
'administrators' => array(
'model' => 'Contact',
'through' => 'building_administrators',
'foreign_key' => 'building_id'
),
);
}
After quering $building->administrators->find_all();
i get error:
Unknown column 'building_administrators.administrator_id' in 'on clause' [ SELECT ..
Is there any way to solve this?
I can solve it by renaming administrator alias to contacts, but then i have to query with $building->contacts->find_all()
and that's not good (maybe i have a administrations and brokers for example).
I can also rename contact_id to administrator_id in database table, but then DB structure is wrong - i don't have administrators table.
Upvotes: 0
Views: 216
Reputation: 3204
Try adding 'far_key' => 'contact_id'
, to the array.
Some background: foreign_key
is the keyname $this
object has in the relationship description, far_key
is the keyname the external object has in the relationship
EDIT: Just wanted to add that Kohana, if the required keys are missing, guesses her own keynames based on the alias name ( http://kohanaframework.org/3.3/guide-api/ORM#get )
Upvotes: 1