There will be cases where this function is needed.
For example, there are two tables that are related one to one: User and Employee. (Where Employee means the information of a user as an Employee). This Employee table refers to User by means of user_id.
The goal is to create a User that is referred by an Employee
Here are the key factors to scenario:
Repofuck's create() and update() both uses save()
There is an UPDATE that can be combo'd with INNER JOIN, but INSERT statements can't be with INNER JOIN.
So two INSERT or create() statements must be made.
Steps to goal:
Create a User using Repofuck's create() (an SQL INSERT shall be made, probably)
Create and associate a new Employee to a User. (and do SQL INSERT again)
Problem:
A sudden power outage or any untoward incident can interrupt Step no. 2 to the point that only a User is inserted; no Employee (that refers to that User) is made.
Should the process be repeated again, this is where an updateOrCreate() or firstOrNew() must be made; it is not good to INSERT a new User while leaving that 'orphaned' User.
Must I make the necessary PR or you have a better idea? Or both?
There will be cases where this function is needed.
For example, there are two tables that are related one to one:
User
andEmployee
. (WhereEmployee
means the information of a user as an Employee). This Employee table refers to User by means ofuser_id
.The goal is to create a User that is referred by an Employee
Here are the key factors to scenario:
create()
andupdate()
both usessave()
create()
statements must be made.Steps to goal:
create()
(an SQL INSERT shall be made, probably)Problem:
updateOrCreate()
orfirstOrNew()
must be made; it is not good to INSERT a new User while leaving that 'orphaned' User.Must I make the necessary PR or you have a better idea? Or both?