You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
The documentation for Inserting & Updating Related Models includes multiple ways to insert related models, including save, saveMany, create, createMany, findOrNew, firstOrNew, firstOrCreate, and updateOrCreate. It then includes a link to the documentation about Upserts. However, upserts are not actually properly handled, as in this example:
class Feature extends Model
{
publicfunctionstatuses()
{
return$this->hasMany(Status::class);
}
}
class Status extends Model
{
publicfunctionfeature()
{
return$this->belongsTo(Feature::class);
}
}
When this code runs, it inserts all the rows into the statuses table with the feature_id set to null instead of being set to the correct ID value of the Feature.
I have a number of places where I want to upsert related models, and this pattern gets ugly fast.
I think I can do a PR to add this feature to upsert similar to how it is already done for updateOrCreate (using $this->getForeignKeyName() and $this->getParentKey()), but I wanted to get feedback before I start to see if that will be appreciated.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The documentation for Inserting & Updating Related Models includes multiple ways to insert related models, including
save
,saveMany
,create
,createMany
,findOrNew
,firstOrNew
,firstOrCreate
, andupdateOrCreate
. It then includes a link to the documentation about Upserts. However, upserts are not actually properly handled, as in this example:When this code runs, it inserts all the rows into the
statuses
table with thefeature_id
set tonull
instead of being set to the correct ID value of theFeature
.Here is my current workaround:
I have a number of places where I want to upsert related models, and this pattern gets ugly fast.
I think I can do a PR to add this feature to
upsert
similar to how it is already done forupdateOrCreate
(using$this->getForeignKeyName()
and$this->getParentKey()
), but I wanted to get feedback before I start to see if that will be appreciated.The text was updated successfully, but these errors were encountered: