laravel first0rNew Integrity Constraint Violation

牧云@^-^@ 提交于 2019-12-10 20:39:38

问题


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.


回答1:


Laravel 4.2 doesnt support composite keys!



来源:https://stackoverflow.com/questions/28889236/laravel-first0rnew-integrity-constraint-violation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!