Nested relation form
Hi guys, is it possible to create form with nested relations?
On my
ClientResource
I have form like this. My entity model is created, but address model is not. I am not sure, if it is even possible.12 Replies
It doesn't create the address when creating, but it does when editing.
Nested relations work. Just for the records if you think about nested resources read https://filamentphp.com/community/alexandersix-filament-what-to-expect-in-2024#nested-resources as well
If you need extra logic, you can manipulate how the save process is treated with the
saveRelationshipsUsing(callback)
method
But in general it should work without any extra logic!So, the code I posted above should work, and if it doesn't, is the problem somewhere on my end?
Here is an working example:
This works
In my example Client belongsTo Entity that belongsTo Address, but when I am creating new client, it is created, also entity is created, but address not. When I edit that client and fill out also address fields, it is created now (only on edit).
I have nested relation like this:
ah. this is nested, nested 😄
so we are talking about $client->entity->address
Right!
Works in the same way:
Can you try it with just belongsTo relations? I am not sure if it matters, but maybe like this:
In my example, a country has ONE
capitalCity
of type City
and a city has ONE mainDistrict
of type District
. So Country>City>District
In your example, a city belongs to a district and a district belongs to a country. So Country>District>City