-
-
Notifications
You must be signed in to change notification settings - Fork 373
feat: add eager_validate? option to manage_relationship/4 #2663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5608,6 +5608,12 @@ defmodule Ash.Changeset do | |
| doc: | ||
| "Validates that any referenced entities exist *before* the action is being performed, using the provided domain for the read." | ||
| ], | ||
| eager_validate?: [ | ||
| type: :boolean, | ||
| default: false, | ||
| doc: | ||
| "Validates that any referenced entities exist *before* the action is being performed, using the domain configured on the related resource." | ||
| ], | ||
| on_no_match: [ | ||
| type: :any, | ||
| default: :ignore, | ||
|
|
@@ -6018,6 +6024,22 @@ defmodule Ash.Changeset do | |
| add_error(changeset, error) | ||
|
|
||
| relationship -> | ||
| {opts, keyword_opts} = | ||
| if opts.eager_validate? && !opts.eager_validate_with do | ||
| domain = Ash.Resource.Info.domain(relationship.destination) | ||
|
|
||
| if !domain do | ||
| raise ArgumentError, | ||
| "Cannot use `eager_validate?: true` because #{inspect(relationship.destination)} " <> | ||
| "does not have a domain configured. Use `eager_validate_with: YourDomain` instead." | ||
| end | ||
|
Comment on lines
+6031
to
+6035
|
||
|
|
||
| new_opts = %{opts | eager_validate_with: domain} | ||
| {new_opts, ManageRelationshipOpts.to_options(new_opts)} | ||
| else | ||
| {opts, keyword_opts} | ||
| end | ||
|
Comment on lines
+6027
to
+6041
|
||
|
|
||
| key = | ||
| opts.value_is_key || | ||
| changeset.resource | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
eager_validate?option doc doesn’t mention that it will raise when the destination resource has no configured domain (and thateager_validate_withcan be used instead / takes precedence). Consider updating the option docs to reflect the actual behavior so callers know when/why it errors.