Hello,
Thanks for a cool module. I’m just getting into ORM and HMVC and I’m using your gas orm 2 and the MX 5.4 hmvc implementation.
I can’t seem to work out how to load the ‘many’ side of the relationship in regards to form building.
Case:
I have a part that has a category. Categories can have many parts. I have defined the has_many and belongs_to relationships in the models.
Here is the part model _init().
self::$relationships = array (
'category' => ORM::belongs_to('\\Model\\Category')
);
self::$fields = array(
'id' => ORM::field('auto[11]'),
'name' => ORM::field('char[255]', array('required','max_length[255]')),
'description' => ORM::field('string', array('required')),
'category_id' => ORM::field('int[11]'),
'partnumber' => ORM::field('char[255]'),
'manufacturer_partnumber' => ORM::field('char[255]'),
'modified_at' => ORM::field('datetime'),
'created_at' => ORM::field('datetime'),
);
here is the category model _init().
self::$relationships = array (
'part' => ORM::has_many('\\Model\\Part')
);
self::$fields = array(
'id' => ORM::field('auto[11]'),
'name' => ORM::field('char[255]', array('required','max_length[255]')),
'prefix' => ORM::field('char[255]', array('required','max_length[255]') ),
'related_to' => ORM::field('char[255]'),
'modified_at' => ORM::field('datetime'),
'created_at' => ORM::field('datetime'),
);
$this->ts_fields = array('modified_at','[created_at]');
Now when creating a part I would like to load all the categories that are available and populate a dropdown with these categories. I assumed that I would be able to just pass the following call in my part controller to my part form view and then manipulate the variable in the view:
$data['categories'] = Model\Category\Category::all();
$this->load->view('includes/template', $data);
But when I load the form I get a code igniter error that it can’t find the categories variable. If i print_r the $data[‘categories’] variable before parsing it to the view then I get a complete variable dump with all the data in there. Am I missing something?
All the examples using Gas ORM 2 that I can find seem to be fairly simple and don’t really show any real world examples of anything.
Thanks in advance.