I am sure its something basic that I am missing.
I have following models
project_categories_model
projects_model
project_images_model
the idea is that categories have many projects have many images, I am trying to get tree functionality working and link these modules together so I may upload multiple images when defining projects, or add a category when defining a project etc. am I using has_many incorrectly?
//in project_images_model
public $has_many = array('project_id' => array(FUEL_FOLDER => 'project_images_model');
//in projects_model
public $has_many = array('project_id' => array(FUEL_FOLDER => 'project_categories_model');
Comments
1. Can a project belong to only one category?
2. Will the images be associated to only one project?
Image can be associated with one project (n:1) where n=images
// in the projects model public $foreign_keys = array('category_id' => array(FUEL_FOLDER => 'fuel_categories_model'));
// in the projects model public $foreign_keys = array('project_id' => 'projects_model');
Although the dropdown for the category in the projects form will automatically be generated, the images will need to actually be manually added in the forms_fields method. You could do something like this:
... if (!empty($values['id'])) { $CI =& get_instance(); $CI->load->module_model('project_images_model'); $images = $CI->project_images_model->options_list('id', 'name', array('project_id' => $values['id'])); $str = ''; foreach($images as $key => $image) { $edit_uri = ($CI->fuel->admin->is_inline()) ? 'inline_edit' : 'edit'; $str .= '<a href="'.fuel_url('project_images/'.$edit_uri.'/'.$key).'">' . $image . '</a><br>'; } $create_uri = ($CI->fuel->admin->is_inline()) ? 'inline_create' : 'create'; $str .= '<br><br><a href="'.fuel_url('project_images/'.$create_uri).'" class="btn_field">Add</a><br>'; ...
I understand now the mapping of foreign_keys however the tree functionality is still not working. It just says no data to display.
// in projects_model - this populates the categories properly in form and listing but tree view displays no data
public $foreign_keys = array('project_category_id' => array('category_id' => 'project_categories_model'));
function tree()
{
return $this->_tree('foreign_keys');
}
https://github.com/daylightstudio/FUEL-CMS/commit/8504510f772896a87230281c182b452345445e56
But its only showing one record under each category.
https://github.com/daylightstudio/FUEL-CMS/commit/7215165839dc6cb3537850b249af4b59e8c0ca5e
It is displaying the category's record id for each record under it, when it should be the actual record id of that record.
https://github.com/daylightstudio/FUEL-CMS/commit/e700d0abf783fd8be9836ddef99836b0c730a914