lpmay
lpmay
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
I'll have to spend some more time with the docs tomorrow and see if I can start to wrap my head around this a little better
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Ok - I'm even more confused now.
validate attribute_equals(:role, :unverified), before_action?: false creates failed changests for user records with :role != :unverified as expected.
validate attribute_equals(:role, :unverified), before_action?: true does not create a failed changset for user records with :role != :unverified.
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Thanks for pointing out the before_action? option. Probably not a cut and dry answer, but is using before_action generally the more idiomatic approach, or is it better to rely on the order inside the action?
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Thanks for the clarification, I think I get it. Is it correct to think of it as one_of is validating the changeset while attribute_equals is validating against the resource? My verify action is adding the change to the role attribute, so the changeset one_of validates against does not have a role field to fail on?
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
just as an exercise to kick the tires with
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Sorry for the walls of text, but I also realize I could've been clearer about what I'm doing in the first place: I have a User resource with a :role attribute constrained to be one_of: [:admin, :verified, :unverified]. I want my verify action to move an unverified user to verified but be invalid for any other type of user
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
I realize what I said is kind of confusing - one_of just seems to work differently in general, I've tried with different sized lists too
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
I'm just getting started with Ash so my question is mostly around how to understand the difference, there's either something wrong with one_of or more likely my mental model for how I should use these validations is wrong
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Yea attribute_in and attribute_equals both seem to work exactly as I expect, but one_of with a list of one element works differently
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
The distinction here is still confusing: attribute_in "Validates that an attribute is being changed to one of a set of specific values, or is in the the given list if it is not being changed. " which seems ill-defined for my case where I am changing the attribute, but not to one of the specified values one_of " Validates that an attribute’s value is in a given list" - seems more like what I'm going for but obviously doesn't work how I expect
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
hmm so attribute_in works as I expect one_of to work, so clearly there is some distinction I don't quite get yet
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
yea ok I just did it again - exact same order, but if the validate clause uses attribute_equals I can generate invalid changesets, but not with one_of
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Am I maybe completely misusing this feature? Are validations just to make sure the attributes are consistent after the action, but I'm trying to use them to gate which resources the action can run on in the first place?
36 replies
AEAsh Elixir
Created by lpmay on 7/18/2023 in #support
Confused about `one_of` vs `attribute_equals`
Hmm Ok the in order thing is good to know - but I think I've tried it with the order the same but the behavior of attribute_equals and one_of with a list of one is not the same
36 replies
AEAsh Elixir
Created by lpmay on 7/17/2023 in #support
Can You Add Additional Attributes to ash_authentication_phoenix?
So can confirm, that did the trick! Thank you @dblack for the help!
6 replies