Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Bulk-updating Related Items using from_array() tries to Insert not Update
  • I am trying to bulk update a table full of Related items on an invoice.
    I am pushing a json array of objects that have all of the $_properties the Model expects.

    My Controller method looks like this:

    public function update_items($invoice_id)
    {
    $invoice = Model_Invoice::find($invoice_id);

    if ($items = MyInput::json())
    {
    $invoice->from_array(array('invoice_items' => $items));
    }

    $invoice->save();
    }

    This gives a PK Collision error when saving the Related objects (invoice_items).
    This is because the objects that have been updated in the $invoice->invoice_items are all is_new() == true.

    How should I be structuring this code? I don't want to have to manage add/edit/delete states for every incoming related item.

  • never mind; it wasn't working.

Howdy, Stranger!

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

In this Discussion