Problems using $this->db->save_related

edited March 2012 in Modules
I'm building a simple module that will manage a table that will have a couple of cross-reference tables with it. I'm trying to go off the simple module example when saving the xref data, but am currently getting the error:
Fatal error: Call to undefined method stdClass::save() in /fuel/application/core/MY_Model.php on line 1140

I have building_model with the following code:

public function on_after_save($values)
{
$data = $this->normalized_save_data['amenities'];
$this->save_related('Building_amenities_xref_model', array('building_id'=>$values['id']),array('amenity_id'=>$data));
}

I also have building_amenities_xref_model that looks like:

class Building_amenities_xref_model extends MY_Model
{
public $record_class = "buildings_amenities_xref";
public $foreign_keys = array('building_id'=>"buildings_model","amenities_id"=>"buildings_amenities_model");

public function __construct()
{
parent::__construct('building_amenities_xref');
}
}

The table building_amenities_xref has just building_id and amenity_id fields in it. I have a feeling I'm just missing something or don't have something configured correctly, but I haven't been able to track it down yet. Any suggestions would be appreciated.

Comments

  • edited 2:18AM
    Hi,
    Adding the record class to building_amenities_xref_model.php should solve the problem:
    class Buildings_amenities_xref_model extends Data_record {

    }
    Regards.
  • edited 2:18AM
    I could have sworn I tried that before. That did the trick, thanks!
Sign In or Register to comment.