HasOne::ofMany creating a model #4356
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I asked this in the Discord channel, because the documentation is frankly misleadingly suggestive on this point. It's not currently possible to do this. Although they are working on being able to inline create hasMany (which is essentially what a hasOne::ofMany is) with no guarantees it actually ends up in the product any time soon. Documentation currently states basically:
At no point does it say: "HasOne can't do both of these things at the same time" The way I got around it, which is a bit of a code smell, is on my Model to do this: public function versions() {
return $this->hasMany(ConfigVersion::class, "config_id");
}
public function version_insert() {
return $this->hasOne(ConfigVersion::class, "config_id");
} And on my resource to do this: Fields\HasOne::make('Version', 'version_insert', ConfigVersion::class)->onlyonForms(true)->hideWhenUpdating(true),
Fields\HasMany::make(__("Versions"), "versions", ConfigVersion::class), |
Beta Was this translation helpful? Give feedback.
-
Has One of Many is essentially a snapshot of Has Many state (eg: Latest Post, Oldest Post, Latest Post from Last Quarter). Therefore it can be considered a read-only field. Furthermore, while we can add a "Create Resource" button and redirect it to the relevant resource create URL, the created resource may not comply with the relationship requirement, especially for Advanced Has One of Many and we still going to have people arguing over this (for bad UI/UX and misleading). |
Beta Was this translation helpful? Give feedback.
-
i understand your point of view, but blocking users to create the resource in not the best solution. |
Beta Was this translation helpful? Give feedback.
Has One of Many is essentially a snapshot of Has Many state (eg: Latest Post, Oldest Post, Latest Post from Last Quarter). Therefore it can be considered a read-only field. Furthermore, while we can add a "Create Resource" button and redirect it to the relevant resource create URL, the created resource may not comply with the relationship requirement, especially for Advanced Has One of Many and we still going to have people arguing over this (for bad UI/UX and misleading).