Create action with multiple nested resources
This is the action to register an account. There are 3 resources at play. An account has many memberships and every membership belongs to a user. The membership resource is simply as has_and_belongs_to_many with a role on it.
When a new account is created, it should always create the account and membership for the owner/user. The user resource has an identity on email and is only created if the user doesn't already exist.
What happens is the membership fails to insert because the user_id is nil.
8 Replies
Hey there! Sorry it took me so long to get back to you
I'd have to see all of the actions in question, but I think especially given that these are create actions, you might be best served with a much simpler pattern of issuing creates/upserts instead of managing relationships.
That makes a lot of sense. I didn’t consider using after_action.
What am I doing wrong? It's not attempting the upsert because the eager check fails but removing the eager check causes a DSL error.
here's my test output. The first two inserts are part of the setup. The query is the eager check, I assume.
What DSL error do you get without the
eager_check_with
?🤔 I see
I've just pushed something up to main that might help
Sorry, that actually probably broke stuff, lemme fix
Was just looking at the Ash CI errors
okay, should be good now 🙂
Checking it out
works! 🎉