Relationship error in EditResource
Hi everyone!
I'm facing an issue with relations in my EditResource.
The relation elements are not all loading properly.
For example, DatePicker fields are not filled with relation data, but the title field works fine.
Tables structure:
table_1:
id
published (bool)
completed (bool)
table_2:
id
table_1_id
start (date)
end (date)
title (string)
content (text)
Model relation: hasOne
from table_1 to table_2
Edit form code:
Issue: Only the title field loads correctly, but start and end DatePicker fields remain empty even though the data exists in the database.6 Replies
Is
start
and end
casted as a date object?
It might be an issue that you use ->relationship('infos')
twiceYes, both start and end are properly casted as datetime:
But can we use the relationship() method multiple times across different components (like Section, Grid, etc.) that need to access the same related attributes? Or is it limited to a single usage per form?
I'm not sure. Did you try only using one?
Yes, I tried using only one. I also tested using the dot notation (relation.column), but the issue remains.
Interestingly, it works when I change the order of the Sections in the form. However, this creates another problem, as I need to keep a specific layout and order for the form fields.
That really sounds like one is overwriting the other one
yes i think, so how it work ?
In the doc it's mentionned : https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-relationships
"This functionality is not just limited to fieldsets - you can use it with any layout component. For example, you could use a Group component which has no styling associated with it:"
But in the same form, we cannot use multiple relationship() ?
I need to alternate between fields from the related model (via relationship()) and fields from the primary model multiple times within the same form. I think it might be possible.