TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
3 ways relationship through ORM?
  • Is that possible? I am using 'through' with 'far_key' and 'foreign_key' but every time in my pivot table (users_items_descriptions) I got records doubled:

    user_id, item_id, description_id - (1, 27, 0) (0, 27, 50), on first row description_id is not stored, on the second user_id.

    Regards

  • pivot table is made for 2 correlating items only. the third item is usually extra data, that is best to keep it serialized, like with json_encode. If you want to correlate 3 items, make 3 separate tables:

    user_id, item_id

    item_id, description_id

    user_id, description_id

    thats the rough play of RDBMS

  • How useful would be to create a kind of joining table: id, user_id, item_id, description_id. When user can have many items and items can have may descriptions.

    Is that good call for the ORM?

  • I do not know if that is a right way, but I use this piece of ORM:

    $descriptions = ORM::factory('description')
            ->where('user_id', '=', '1')
            ->join('details', 'INNER')
            ->on('details.description_id','=','description.id')
    
            ->find_all();
    

    That is how I am fetching from the description table, that looks like that:

    id  score   comment 
    19  14  Lorem ipsum dolorent sub imen da
    20  14  blahblahblah
    

    while details, looks like that:

    id  item_id     description_id  user_id 
    11  20  19  1
    12  21  20  1
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion