laravel first0r新的完整性约束违规 [英] laravel first0rNew Integrity Constraint Violation
问题描述
我使用Laravel Eloquent的firstOrNew()函数根据3个条件检索DB记录:
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,
));
我还有这3个字段的唯一复合键。
I also have a unique composite key of those 3 fields.
即使记录存在,该函数也无法检索,所以当我更新属性并运行 $ summary-> save()
I获得精彩的
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]:完整性限制违规:1062重复条目>'2015-01-02-6-23' key'date_product_store_unique'
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry >'2015-01-02-6-23' for key 'date_product_store_unique'
任何想法?
Laravel版本是4.2。
Laravel version is 4.2.
推荐答案
Laravel 4.2不支持复合键!
Laravel 4.2 doesnt support composite keys!
这篇关于laravel first0r新的完整性约束违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!