andrewb
1
Hi,
I am trying to get the id of a role so I can add it as an assoc:
Repo.get_by!(Role, name: "account_owner", prefix: subdomain)
When I do this I get an error:
field prefix
in where
does not exist in schema
It seems to think the prefix is a field. I am using Ecto 3.0.1 and it lists prefix as an option for the query. Does anyone have any suggestions?
Thanks
Try this instead,
Repo.get_by!(Role, [name: "account_owner"], prefix: subdomain)
The prefix
needs to be the third argument to get_by!/3
. The way you have is the same as doing:
Repo.get_by!(Role, [name: "account_owner", prefix: subdomain])
and Ecto thinks prefix is part of your clauses
.
3 Likes
andrewb
3
@sjoconnor thank you … worked as expected.
I had reverted to using Repo.Query
but this is much cleaner.
Thanks again
1 Like