spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Add a many-to-many relation. #22

Closed spadefoot closed 12 years ago

spadefoot commented 12 years ago

It has been recommended that the LEAP ORM implement a many-to-many relation for handling such relationships. This would be in addition to the currently supported relations.

bluesnowman commented 12 years ago

The ORM can now create a "has many through" relation by adding the following metadata to a "has many" relation definition:

$this->relations = array(
    ...
    'users_roles' => new DB_ORM_Relation_HasMany($this, array(
        'parent_key' => array('uID'),
        'through_model' => 'user_role',
        'through_keys' => array(
            array('uID'), // matches with parent
            array('rID'), // matches with child
        ),
        'child_model' => 'role',
        'child_key' => array('rID'),
    )),
    ...
);