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
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration
{
/** * Run the migrations. */publicfunctionup(): void
{
Schema::create('fathers', function (Blueprint$table) {
$table->increments('id_father');
$table->string('name');
$table->timestamps();
});
}
/** * Reverse the migrations. */publicfunctiondown(): void
{
Schema::dropIfExists('fathers');
}
};
and
<?phpuseIlluminate\Database\Migrations\Migration;
useIlluminate\Database\Schema\Blueprint;
useIlluminate\Support\Facades\Schema;
returnnewclassextends Migration
{
/** * Run the migrations. */publicfunctionup(): void
{
Schema::create('sons', function (Blueprint$table) {
$table->increments('id_son');
$table->string('name');
$table->unsignedInteger('father_id')->nullable();
$table->timestamps();
$table->foreign('father_id')->references('id_father')->on('fathers');
});
}
/** * Reverse the migrations. */publicfunctiondown(): void
{
Schema::dropIfExists('sons');
}
};
Examples:
FATHER
I would like to create a father with 2 children.
Using POST on Father:
{
"name": "new father no1", // new `Father`"sons": [
{
"name": "new son n1"// new `Son`
},
{
"name": "new son no2"// new `Son`
}
]
}
It is supposed to create 1 new Father and 2 new Son but i returns:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sons'in'field list'
The same if instead of creating 2 new Son I just create a new father and relate it with 2 existing Son:
{
"name": "new father no1", // new `Father`"sons": [
{
"name": "son n1"// existing `Son`
},
{
"name": "son no2"// existing `Son`
}
]
}
The same using IRI:
{
"name": "new father no1", // new `Father`"sons": [
"/api/sons/3", // existing `Son`"/api/sons/4"// existing `Son`
]
}
SON
I would like to create a new Son with a new Father.
Using POST on Son
{
"name": "new son", // new `Son`"father": {
"name": "new father"// new `Father`
}
}
It is supposed to create 1 new Son and a new Father but a new Son with no Father is created.
Creating a new Son related to an existing Father using IRI:
{
"name": "new son", // new `Son`"father": "/api/fathers/2"// exsiting `Father`
}
It actually creates the new Son with the proper existing Father
I would like to update Father's name from Son.
Using PATCH on Son with id = 1:
{
"name": "changing new of son 1", // exsting `Son`"father": {
"@id": "/api/fathers/2", // related `Father`"name": "new fathres name"
}
}
The father's name does not change.
I didn't add all the possibilities using POST, PATCH and PUT but I think the problem can be understood with the previous examples.
Possible Solution
On a Symfonycasts course API Platform 3 Part 1: Mythically Good RESTful APIs I've seen something called cascade: ['persist']here and here not sure how to reproduce it on Laravel if it is needed.
Also, I am not sure if some kind of additional denormalization is needed neither because I didn't see anything related on Documentation, although I am aware Larave'ls one still need some improvements. In that case, could someone explain how to do it?
Thank you
The text was updated successfully, but these errors were encountered:
API Platform version(s) affected: 4.0.12
Description
When trying to create, replace or update an embbeded relation using POST, PUT or PATCH Operations, that embedded relation is not modified.
As far as I know, using denormalization we should be able to create, replace or update and embbeded relation using its fields instead of IRI.
How to reproduce
Having a couple of simple Models,
Father
andSon
, defined as following:and
Created using following migrations:
and
Examples:
FATHER
Using POST on
Father
:It is supposed to create 1 new
Father
and 2 newSon
but i returns:The same if instead of creating 2 new
Son
I just create a new father and relate it with 2 existingSon
:The same using IRI:
SON
Son
with a newFather
.Using POST on
Son
It is supposed to create 1 new
Son
and a newFather
but a newSon
with noFather
is created.Creating a new
Son
related to an existingFather
using IRI:It actually creates the new
Son
with the proper existingFather
Father
's name fromSon
.Using PATCH on
Son
with id = 1:The father's name does not change.
I didn't add all the possibilities using POST, PATCH and PUT but I think the problem can be understood with the previous examples.
Possible Solution
On a Symfonycasts course API Platform 3 Part 1: Mythically Good RESTful APIs I've seen something called
cascade: ['persist']
here and here not sure how to reproduce it on Laravel if it is needed.Also, I am not sure if some kind of additional denormalization is needed neither because I didn't see anything related on Documentation, although I am aware Larave'ls one still need some improvements. In that case, could someone explain how to do it?
Thank you
The text was updated successfully, but these errors were encountered: