Rebecca Le
Rebecca Le
AEAsh Elixir
Created by Rebecca Le on 7/7/2023 in #support
Broadcasting pubsub update notifications only if the resource has been changed?
issue created https://github.com/ash-project/ash/issues/647 so I'll close this thread
12 replies
AEAsh Elixir
Created by Rebecca Le on 7/7/2023 in #support
Broadcasting pubsub update notifications only if the resource has been changed?
I think configuring it in the notifier would be better
12 replies
AEAsh Elixir
Created by Rebecca Le on 7/7/2023 in #support
Broadcasting pubsub update notifications only if the resource has been changed?
ah right, if you had an update action that doesn't touch the resource itself, but uses hooks to do related stuff, you still want to know about it. that makes sense
12 replies
AEAsh Elixir
Created by Rebecca Le on 7/7/2023 in #support
Broadcasting pubsub update notifications only if the resource has been changed?
it seems like a sensible default to me, but it would definitely be a breaking change if anyone was relying on the old behaviour. i can't think of an example of when the current behaviour would be wanted though. for atomic operations (or any case where it can't be known if something happened or not) we should probably default to sending the notification
12 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
I got this to work 😄 My resource code:
create :create do
primary? true
argument :run_external_validations, :boolean, default: true, private?: true

validate {Vendor.CredentialValidation, []},
only_when_valid?: true,
before_action?: true,
where: argument_equals(:run_external_validations, true)
create :create do
primary? true
argument :run_external_validations, :boolean, default: true, private?: true

validate {Vendor.CredentialValidation, []},
only_when_valid?: true,
before_action?: true,
where: argument_equals(:run_external_validations, true)
My test factory code:
defp insert_vendor_params!(params) do
Vendor
|> Changeset.new(params)
|> Changeset.set_argument(:run_external_validations, false)
|> Changeset.for_create(:create, authorize?: false)
|> MyApp.Api.create!()
end
defp insert_vendor_params!(params) do
Vendor
|> Changeset.new(params)
|> Changeset.set_argument(:run_external_validations, false)
|> Changeset.for_create(:create, authorize?: false)
|> MyApp.Api.create!()
end
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
I can add one in my project and then contribute it back 👍
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
okay so I'm definitely using it very wrong
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
the docs say
Validations that should pass in order for this validation to apply. These validations failing will not invalidate the changes, but will instead result in this validation being ignored. Accepts a module, module and opts, or a 1 argument function that takes the changeset. Defaults to [] .
so its not "return a boolean to run", but I don't know what it is
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
I think I'm not understanding how to run the validation conditionally. I've tried:
create :create do
argument :run_external_validations, :boolean, default: true, private?: true

validate {Vendor.CredentialValidation, []},
only_when_valid?: true,
before_action?: true,
where: &Ash.Changeset.get_argument(&1, :run_external_validations)
create :create do
argument :run_external_validations, :boolean, default: true, private?: true

validate {Vendor.CredentialValidation, []},
only_when_valid?: true,
before_action?: true,
where: &Ash.Changeset.get_argument(&1, :run_external_validations)
but that seems to always skip it
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
I'll take a look at doing this shortly and mark resolved if I can get it all working 🙂
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
that would be doable, given I only do it a few places in factory methods I think
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
Yeah I thought later maybe I could add an argument to the action to decide whether or not to run the external validation, defaulting to true, set to false in tests
25 replies
AEAsh Elixir
Created by Rebecca Le on 6/12/2023 in #support
Possible to skip validation for an action? (or best practices for working with external credentials)
I have just seen that its possible to skip_global_validations? from inside an action (I'm guessing that would be validations from a validations block on the resource?) so there might be a way to skip validations from outside, hidden somewhere
25 replies
AEAsh Elixir
Created by Stefan Wintermeyer on 2/9/2023 in #support
Which type for Text?
I'm pretty sure using :string will define fields as type text, so not size limited like a varchar
3 replies
AEAsh Elixir
Created by Stefan Wintermeyer on 1/23/2023 in #support
Create a resource including a belongs_to id
In your Location resource:
actions do
create :create do
primary? true
change manage_relationship(:level_id, :level, type: :append_and_remove)
...
actions do
create :create do
primary? true
change manage_relationship(:level_id, :level, type: :append_and_remove)
...
this would allow the level_id attribute to be set when creating a Location, ensuring it's also a valid value etc.
12 replies
AEAsh Elixir
Created by Stefan Wintermeyer on 1/23/2023 in #support
Create a resource including a belongs_to id
in your create action definition, you would use manage_relationship to allow the setting of the level_id - let me grab an example
12 replies