Add required!/1, ash_required/1, and ash_required!/2 (issue #261)#707
Add required!/1, ash_required/1, and ash_required!/2 (issue #261)#707dallingson wants to merge 2 commits intoash-project:mainfrom
Conversation
…ct#261) - required!/1 and ash_required/1: custom expressions for presence in queries (replacing not is_nil(...)) - PostgreSQL ash_required/1 in ash_functions.ex for filters/calculations - Data layer can?(:required_error) and ash_required!/2 (RequiredError): when value is nil, return Ash.Error.Changes.Required; required_error/2 for the error message - Docs and tests for the new expressions and required_error
|
I don't see any particular value in |
SQL function, config, and tests Keep ash_required!/2 + required_error/2 and :required_error data-layer capability, and update docs accordingly
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| defmodule AshPostgres.Functions.RequiredError do |
There was a problem hiding this comment.
This function should also live in ash core. We would just need to add support for it in ash_sql, update the dep here, and then add it to the capabilities list.
There was a problem hiding this comment.
I would love to help get this implemented in ash core if you would like. Do we need to have this in a separate issue for ash core?
There was a problem hiding this comment.
I can also go in and make changes to ash_sql if you would like.
There was a problem hiding this comment.
Please feel free 😄 There are other functions in AshSql and Ash core that you can use as reference. LMK if you have any questions! So first the change in Ash, second the change in AshSql, third the change in AshPostgres.
There was a problem hiding this comment.
Okay, just to clarify. What changes need to be made in ash_sql? As of right now I know that I am moving the required_error to ash core and then updating ash_sql and ash_postgres. I just want to make sure I know what needs to be changed in ash_sql. :)
There was a problem hiding this comment.
Ah, actually 🤔 You wouldn't make any changes in AshSql come to think of it. You can modify the SQL implementation file in ash_postgres to add a handler for the new function in ash core. So we just need to first add the function to ash, and then add an expression handler here 😄 Sorry for misleading.
Pull request: Add required!/1, ash_required/1, ash_required!/2, and required_error/2
Closes #261
What
Adds custom expressions
required!/1andash_required/1for presence in queries, andash_required!/2plusrequired_error/2for required-field validation that returnsAsh.Error.Changes.Requiredwhen a value is nil.Why
There was no built-in way to express "required/present" in filters and calculations without
not is_nil(...), or to get Ash's standard required error from the data layer when a value is nil.How to use
Presence in queries (filters/calculations):
Required-field validation (returns
Ash.Error.Changes.Requiredwhen nil):When the value is nil, Ash uses
required_error/2and the data layer returns the standard required error.Changes
required!/1andash_required/1for presence in queries.required_error/2and data-layer integration so validation returnsAsh.Error.Changes.Requiredwhen nil.ash_required!/2expression that uses the required-error path when the value is nil.can?(:required_error)and registration of the new functions/expressions.ash_required/1in migrations so it's available in SQL.documentation/topics/advanced/expressions.md.required_error_test.exscoverage.Contributor checklist
Leave anything that you believe does not apply unchecked.