I'm using Laravel Eloquent's firstOrNew() function to retrieve a DB record based on 3 criteria:
$summary = $this->firstOrNew(array(
'date' => $date,
'product_id' => $product_id,
'store_id' => $store_id,
));
I also have a unique composite key of those 3 fields.
Even though the record exists, the function doesn't retrieve it, so when I update an attribute and run $summary->save()
I get the wonderful
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry >'2015-01-02-6-23' for key 'date_product_store_unique'
Any ideas?
Laravel version is 4.2.