Php Laravel保存HasOne会创建重复条目
当试图更新我的属性模型和一个地址关系时,我不断地在数据中得到重复的行。 我不希望插入/更新,因为数据完全相同 我在创建或更新属性模型方面没有问题 发行代码Php Laravel保存HasOne会创建重复条目,php,eloquent,laravel-5.6,Php,Eloquent,Laravel 5.6,当试图更新我的属性模型和一个地址关系时,我不断地在数据中得到重复的行。 我不希望插入/更新,因为数据完全相同 我在创建或更新属性模型方面没有问题 发行代码 // save address relation $address = new PropertyAddress($propertyDetails['address']); $property->address()->save($address); 物业模型 字段:id $this->hasOne('
// save address relation
$address = new PropertyAddress($propertyDetails['address']);
$property->address()->save($address);
物业模型
字段:id
$this->hasOne('App\Models\Property\PropertyAddress')
属性地址模型
字段:id、属性\u id、
$this->belongsTo('App\Models\Property\Property')
控制器
$property = Property::with('address')->firstOrNew(
['agency_id' => $propertyDetails['agency_id'], 'external_ref' => $propertyDetails['external_ref'] ]
);
$property->fill($propertyDetails);
$property->save();
// save address relation
$address = new PropertyAddress($propertyDetails['address']);
$property->address()->save($address);
尝试提及外键
$this->hasOne('App\Models\Property\PropertyAddress','Property\u id')
@linuxartisan我已经在这两种模型上尝试过了,但仍然存在相同的问题:$this->hasOne('App\models\Property\PropertyAddress','Property\u id','id')
和$this->belongsTo('App\Models\Property\Property','id','Property\u id')代码>