carlgleisner

carlgleisner

Eager checking on multiple attributes supported?

Is it supported to have eager_check?: true run on identities when the identity consists of more than one attribute?

I have a compound identity that indeed returns errors on submission with Postgres as data layer. On another resource using an identity with a single attribute I do get eager checking on validation however, as one would expect of course.

identities do
    identity :imaginative_party_name, [:host_id, :party_name] do
      eager_check? true
      message "success not possible if you insist on reusing party names all the time"
    end
  end

Looking at the documentation I cannot tell that this would not be supported. If so, then maybe this could be pointed out?

Marked As Solved

carlgleisner

carlgleisner

It works :slightly_smiling_face:

The thing was that I was using argument for the input of the key of the related record together with a change with manage_relationship. As I understand it now this is intended behaviour.

I dug up a few of your messages in the Discord which I think explain it:

I think you [i.e. another person] may be running into an issue around when managed relationships actually happen. Managing relationships is a bit special insofar as the logic to actually do so is handled by calling the action.

So when your validation runs, the technician_id is never going to be set.

You have a few options:

  1. don’t use managed relationships for the belongs_to relationship
  2. run your validation in an after_action hook in a custom change
  3. run your validations in the action, based on the arguments instead

You put examples in there as well, very helpful. Maybe I could copy these here as well if appropriate?

Humbly, maybe a note in the documentation could be of use for others? I’d be happy to provide a PR as a starting point if desirable.

Sidenote

I’m yet to try out the solutions you suggested since for now it’s just fine for me to not use argument+change. But I did wonder whether that also solves not getting errors after submission when passing in input that does not relate to the id of an existing record.

Reference codebase

I used this little reproduction for testing for future reference.

But I guess it’s technically not a “reproduction” when there is no actual issue :slight_smile:

https://github.com/carlgleisner/ash_phoenix_reproduction

EDIT: I should edit the title of this post for posterity

Also Liked

zachdaniel

zachdaniel

Creator of Ash

You would have my utmost gratitude :bowing_man:

This one would probably be a separate issue? Likely has something to do with input names not matching? But curious to see if its still an issue after your change :slight_smile:

zachdaniel

zachdaniel

Creator of Ash

Interesting. It should work :slight_smile: If not then its a bug.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement