Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
deleting relations
  • I just wrote the "add" function for a relation using:

    // both main and related object already exist
    $user = Model_User::find(8);
    $user->posts[1] = Model_Post::find(1);
    $user->save();


    Now, how do I delete the relation?
    -thanks
  • HarroHarro
    Accepted Answer
    The opposite:

    // both main and related object already exist
    $user = Model_User::find(8);
    unset($user->posts[1]);
    $user->save();

    Note that this removes the relation, it does not delete the post. If you want to delete the post, do

    // both main and related object already exist
    $user = Model_User::find(8);
    $user->posts[1]->delete();

    unset($user->posts[1]);
    $user->save();

Howdy, Stranger!

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

In this Discussion