Kohana 3, problem with m2m data adding

Posted by Marek on Stack Overflow See other posts from Stack Overflow or by Marek
Published on 2010-05-06T21:12:21Z Indexed on 2010/05/06 21:18 UTC
Read the original article Hit count: 216

Filed under:
|
|

Hello

I posted this on official forum but with no result.

I am getting :Undefined index: enrollment error when trying to save data.

My pivot model:

class Model_Enrollment extends ORM  {
               protected $_belongs_to = array('page' => array(), 'menugroup' => array());
          }

Model_Page

protected $_has_many = array('templates' => array(), 'menugroups' => array('through' => 'enrollment'));

Model_Menugroup

  protected $_has_many = array('menuitems' => array(), 'pages' => array('through' => 'enrollment'));
//Overriden save() method in Model_Menugroup:
public function save() {
    if (empty($this->created)) {
         $this->created = time();
    }
    parent::save();
    $this->reload();
    if (! $this->is_global) {
      if (! empty($this->groupOwnerPagesId) {
          $page = ORM::factory('page');
          foreach($this->groupOwnerPagesId as $id) {
            $this->add('enrollment', $page->find($id));
          }
       }
    }
}

I did:

  • I corrected table names in pivot model by changing them to singular
  • I even now using the same name for pivot table / model = enrollment. The same as in tutorial. Just in case
  • So the pivot table has name 'enrollment' and has 2 columns: page_id , menugroup_id
  • I tried to add pk in pivot table, but it changed nothing
  • I tried to add/remove db relation between pages/menugroups and pivot table (InnoDB) but with no luck
  • I tried save all data in controller, but with the same bad result:(

I am still getting the same error:

Undefined index: enrollment in ORM line: $columns = array($this->_has_many[$alias]['foreign_key'], $this->_has_many[$alias]['far_key']);

Could somebody tell me, what can be else wrong? I have no other ideas:(

Kind regards

© Stack Overflow or respective owner

Related posts about php

Related posts about kohana