8

I'm using Kohana v3 and ORM, I have two models, Model_A and Model_B related by "has_many" through a pivot table, which has an additional column. I can save data in that column in the pivot table using the third parameter of the add() function, but I can't figure out how to read that column using ORM.

Any ideas? Thanks in advance.

dusan
  • 9,104
  • 3
  • 35
  • 55

1 Answers1

9

You need to create a Model that is based on that pivot table if you want to access that additional column, let say we name it Model_A_B.

class Model_A_B extends ORM {

    protected $_belongs_to = array(
        'A' => array(),
        'B' => array()
    );

}

Then, if $a is an instance of Model_A and $b is an instance of Model_B, we get the Model_A_B instance by calling:

$ab = ORM::factory('A_B', array('A_id' => $a, 'B_id' => $b));

if ($ab->loaded()) {
    // do stuff
}
Lukman
  • 18,462
  • 6
  • 56
  • 66