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.
On the Analyze tab, in the Calculations group, click Fields, Items, & Sets, and then click Calculated Field. In the Name box, type a name for the field. In the Formula box, enter the formula for the field. To use the data from another field in the formula, click the field in the Fields box, and then click Insert Field.
Add an Additional Row or Column Field Click any cell in the PivotTable. The PivotTable Fields pane appears. You can also turn on the PivotTable Fields pane by clicking the Field List button on the Analyze tab. Click and drag a field to the Rows or Columns area.
Change the order of row or column items In the PivotTable, right-click the row or column label or the item in a label, point to Move, and then use one of the commands on the Move menu to move the item to another location.
The Field List should appear when you click anywhere in the PivotTable. If you click inside the PivotTable but don't see the Field List, open it by clicking anywhere in the PivotTable. Then, show the PivotTable Tools on the ribbon and click Analyze> Field List.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With