문제

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.

도움이 되었습니까?

해결책

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 )

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top