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.

Last Post!

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:

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement