3

I'm using Kohana v3 with Database and ORM. I found a nice question which help me add and read additional columns in pivot tables: Kohana 3.0.x ORM: Read additional columns in pivot tables

I got 2 pivot table with additional column. One of those works perfectly but I'm stuck in the unknown with the second.

Got 2 tables, applications and partners plus my pivot table with the next ORM models:

class Model_Application extends ORM
{

    protected $_has_many = array(
        'partners'=>array(
            'model'=>'partner',
            'through'=>'partners_applications',
            )
        );
}

//AND

class Model_Partner extends ORM
{

protected $_has_many = array(
    'applications' => array(
        'model'=>'application',
        'through'=>'partners_applications',
        )
    );

}

//plus my pivot table ORM model

class Model_Partners_applications extends ORM
{

    protected $_belongs_to = array(
            'partner' => array(),
            'application' => array()
        );
}

When I try to get

$instance = ORM::factory('partners_applications',array('partner_id' => $this->partner,'application_id' =>   $this->application))->find();

Kohana keep saying :

ErrorException [ Fatal Error ]: Class 'Model_Partners_applications' not found

I've triple checked Model name constructions but I can't find the error. In Kohana environment debug part, my two firsts models are loaded but not the pivot table.

Any ideas?

Community
  • 1
  • 1
Pioup
  • 31
  • 1

2 Answers2

0

Should be ORM::factory('partners_application'), in Kohana ORM always expects singular form ;)

matino
  • 17,199
  • 8
  • 49
  • 58
  • I think plurial form fits for many to many relationship in Kohana. Anyway, Singular form for partner and/or application send me the same error. – Pioup Apr 23 '12 at 14:57
0

Model_Partners_applications should be inside application/classes/model/partners/applications.php

  • So application/classes/model/partners/applications.php contains : `class Model_Partners_applications extends ORM { protected $_table_name = 'partners_applications'; protected $_belongs_to = array( 'partner' => array(), 'application' => array() ); }` It's not working for me, still the same error and the new class is not even loaded... – Pioup Apr 24 '12 at 08:26