Question

To make relationship between users was created a table that looks like.

sql
CREATE TABLE `friends`(
 `from` INT NOT NULL,
 `to` INT NOT NULL,
 UNIQUE INDEX(`from`, `to`)
 );

As you may know - field from and to is a keys of user_id from users table.

I'm using Kohana 3.09 with its default module Auth.

Question is...

*How to make ORM functionality around relations of users with (default) Model_User class?*

Is there any needle to create additional class or perhaps i had some mistakes with relations one_to_many trouth and many_to_many trouth cause it did not work. Please help. My best regards.

Was it helpful?

Solution

You should check out this section of the documentation:

http://kohanaframework.org/guide/orm/relationships#hasmany

You'll need something like this within your user class

protected $_has_many = array(
    'friends' => array(
        'model' => 'user',
        'through' => 'friends',
        'far_key' => 'from',
        'foreign_key' => 'to',
    )
);

These options are used at this part in the source code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top