Relation Manager
In relation manager for a resource, if the relation is hasOne, how do I stop creation of a another record if one already exists?
Thanks in advance for any help.
10 Replies
You shouldn't use a Relation Manager for HasOne. Use a Layout field like Fieldset
But then I have a different issue. Some instances do not have the relation, i.e., it returns null. In such cases, updating fails saying that some fields are required.
Show your code
IssueResource
?
Sorry, pressed enter instead of shift enter.
The special_issue is the HasOne Relation. Not all issues are special, only some of them.
You could add a Toggle to enable the
special_issue
. Or use ->saveRelationshipsUsing()
to only save when name
is not emptyYes, I have thought about using a toggle to hide / show it. But did want to do it, if there is another cleaner solution. How does one use saveRelationshipsUsing? Should it used on the form component? I am unable to find documentation on that.
Yes, you use it on the fieldset and it overwrites the saving logic. Check the
EntanglesStateWithSingularRelationship::relationship()
method for the default implementation. It's a bit complex though.
Not sure whether we have a cleaner way.
I guess a toggle would be cleaner.Ok. Thanks for the help.