more than one has_many relationship model

edited April 2015 in Modules
i want to add multiple relationship tables in a single model, and i did it like

public $has_many = array(
'Salt' => array('salts/salts_model','relationships_model'=>'compositions/compositions_model'),
'Salt Values' => array('saltvalues/saltvalues_model','relationships_model'=>'saltvaluecompositions/saltvaluecompositions_model')
);

the list boxed working fine, the salt list box is working fine and saving data in the compositions relationship table, but the not in the saltvaluecompositions table, but showing the data in listbox, am i missing anything ?

Comments

  • edited 11:26AM
    Not sure if this will work but what if you use this format:
    'Salt Values' => array('model' => 'saltvalues_model', 'module' => 'saltvalues', 'relationships_model'=>'saltvaluecompositions/saltvaluecompositions_model') );
    This is assuming that your saltvalues_model is in an advanced module folder (fuel/modules/saltvalues/models/saltvalues_model).

    Also, is your saltvaluecompositions lookup table have the same columns as the fuel_relationships table.
  • edited 11:26AM
    sorry for late reply, the above is working fine when i change the value 'Salt_values' instead of 'Salt Values', issue is of a space, works fine if use without space, and yes tried your as well, its also working fine. Yes tables have the same columns and the model is in the advanced folder.
  • edited 11:26AM
    when i call $output = $this->_render($view, $vars, FALSE);
    i get error in the Drugs_base_controller.php on the _render function, error is

    Fatal error: Call to a member function layout() on a non-object in C:\Program Files\Ampps\www\fuelcms\fuel\modules\drugs\libraries\Drugs_base_controller.php on line 32

    i think, its not able to load the values from the config file, because when i pass values to $layout, it bypass it and throws error on

    $uri_path = trim($this->fuel->drugs->config('uri'), '/');

    what i am missing ?
  • edited 11:26AM
    Do you have the block of code that is throwing the error (line 32)? Perhaps maybe the whole method?
  • edited 11:26AM
    here is the code
    function _render($view, $vars = array(), $return = FALSE, $layout='')
    {
    // on this line im getting error (Line 32), if pass default values to the layout, it bypass it and shows error on the next line
    if (empty($layout)) $layout = $this->fuel->drugs->layout();

    // get any global variables for the headers and footers
    $uri_path = trim($this->fuel->drugs->config('uri'), '/');
    $_vars = $this->fuel->pagevars->retrieve($uri_path);
    if (is_array($_vars))
    {
    $vars = array_merge($_vars, $vars);
    }
    $view_folder = $this->fuel->drugs->theme_path();
    $vars['CI'] =& get_instance();

    $page = $this->fuel->pages->create();
    if (!empty($layout))
    {
    $vars['body'] = $this->load->module_view($this->fuel->drugs->config('theme_module'), $view_folder.$view, $vars, TRUE);
    $view = $this->fuel->drugs->theme_path().$this->fuel->drugs->layout();
    }
    else
    {
    $view = $view_folder.$view;
    }
    $vars = array_merge($vars, $this->load->get_vars());
    $output = $this->load->module_view($this->fuel->drugs->config('theme_module'), $view, $vars, TRUE);
    $output = $page->fuelify($output);

    if ($return)
    {
    return $output;
    }
    else
    {
    $this->output->set_output($output);
    }
    }
  • edited 11:26AM
    Is "drugs" an advanced module located at fuel/modules/drugs/ and is it enabled in fuel/application/config/MY_fuel.php $config['modules_allowed']
  • edited 11:26AM
    yes, its advanced module, and enabled in the my_fuel, working fine in backend (admin), but when im trying to show them in frontend, getting the above error
  • edited 11:26AM
    In the front end, if you are using it in a view, try using $CI->fuel... instead of $this->fuel...
  • edited 11:26AM
    getting the same error, even after using the $CI->fuel
  • edited 11:26AM
    Are you able to var_dump on $this->fuel->drugs to determine what type of object (if one exists at all) there? The Fuel.php class should be lazy loading in the fuel/modules/drugs/libraries/Fuel_drugs.php class to exist at $this->fuel->drugs...
Sign In or Register to comment.