[eluser]tolyx[/eluser]
I'm tearing my hair out over a problem which I simply don't understand.
I have two objects - a portfolio has many work_examples. I'm trying to save a new work_example against a portfolio. So my shortened controller code is...
Code:
// If an id has been provided
$portfolio = new Portfolio();
$portfolio->where('id', $portfolio_id);
$portfolio->get();
$work_example = new Work_Example();
// Save the item
$work_example->image_file_name = $image_file_name;
$work_example->vimeo_id = $this->input->post('vimeo_id');
$work_example->description = $this->input->post('description');
if ($work_example->save($portfolio))
{
// Write a flash message
$this->session->set_flashdata('message', 'The work example has been saved successfully.');
var $has_one = array('carousel_item');
var $has_many = array('work_example', 'feature', 'discipline', 'case_study');
In my work example model...
Code:
var $has_one = array('portfolio');
(The portfolio_id is on the table, rather than a join table.)
So when the work example is saved, all fields save correctly other than the portfolio_id, which is 0. The portfolio has been retrieved successfully and I can echo the fields of the portfolio as expected. Saving using $portfolio->all makes no difference.
I also have validation on the work example that requires a portfolio, yet an error message is returned saying 'Portfolio is a required relationship'.