Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to update related objects
  • Here is the example  and comments.


    // Fetch projects with related project_langs
    $project = Model_Admin_Project::find($project_id, array(
    'related' =--> array(
    'project_langs' => array(
    'where' => array(
    array('language_id', '=', $this->current_language->id)
    )
    )
    )
    )
    );

    //update project property
    $project->set(array(
    'applicant' => \Input::post('applicant')
    ));

    /*I have one object in $project->project_langs, but when i update its property all project_langs rows collumns 'title' got updated. Why? I just wanted to update related object that I selected.
    */

    $project->project_langs->set(array(
    'title' => \Input::post('project_title')
    ));

    $project->save();

  • I haven't got a clue. set() operates on the current object, and only sets the property in it's own data container.

    Can you run this code with the profiler on, and check which update queries are run when you save?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion