Association not working. Is 'property' a reserved name?

I am trying to associate one resource with another. This works well for most resources I have. However there's this one resource called 'Property' that I can' get to associate with any other resource. If you see this code after submitting a form:
form #=> #AshPhoenix.Form<
resource: Clients.Goal,
action: :create,
type: :create,
params: %{
"agency_id" => "c0863320-cd12-4334-9e19-de769f9d4add",
"client_id" => "500ad228-3f76-4754-a081-f7c5659fce3d",
"property_id" => "59131003-cefd-48af-8fe3-0bc16cc6d7c8",
"title" => "fqds"
},
source: #Ash.Changeset<
api: Clients,
action_type: :create,
action: :create,
attributes: %{
agency_id: "c0863320-cd12-4334-9e19-de769f9d4add",
client_id: "500ad228-3f76-4754-a081-f7c5659fce3d",
id: "4063e291-bae0-4f79-b550-e8227f906d5c",
title: "fqds"
},
form #=> #AshPhoenix.Form<
resource: Clients.Goal,
action: :create,
type: :create,
params: %{
"agency_id" => "c0863320-cd12-4334-9e19-de769f9d4add",
"client_id" => "500ad228-3f76-4754-a081-f7c5659fce3d",
"property_id" => "59131003-cefd-48af-8fe3-0bc16cc6d7c8",
"title" => "fqds"
},
source: #Ash.Changeset<
api: Clients,
action_type: :create,
action: :create,
attributes: %{
agency_id: "c0863320-cd12-4334-9e19-de769f9d4add",
client_id: "500ad228-3f76-4754-a081-f7c5659fce3d",
id: "4063e291-bae0-4f79-b550-e8227f906d5c",
title: "fqds"
},
You'll notice I'm submitting property_id in params. However it is not in the attributes section from the source. Not sure why that is. I have:
create :create do
primary? true
argument(:client_id, :uuid)
argument(:agency_id, :uuid)
argument(:property_id, :uuid)

change(manage_relationship(:agency_id, :agency, type: :append))
change(manage_relationship(:client_id, :client, type: :append))
change(manage_relationship(:property_id, :property, type: :append))
end
create :create do
primary? true
argument(:client_id, :uuid)
argument(:agency_id, :uuid)
argument(:property_id, :uuid)

change(manage_relationship(:agency_id, :agency, type: :append))
change(manage_relationship(:client_id, :client, type: :append))
change(manage_relationship(:property_id, :property, type: :append))
end
and
relationships do
belongs_to :agency, Accounts.Agency do
allow_nil?(false)
api(Accounts)
end

belongs_to :client, Accounts.Client do
allow_nil?(false)
api(Accounts)
end

belongs_to(:property, Clients.Property)
end
relationships do
belongs_to :agency, Accounts.Agency do
allow_nil?(false)
api(Accounts)
end

belongs_to :client, Accounts.Client do
allow_nil?(false)
api(Accounts)
end

belongs_to(:property, Clients.Property)
end
So I can associate accounts and clients, but not properties using the same-ish code. Just wondering if I may need to call my Property resource something else? The form submit shows there's errors, but does't say what the actual errors are. So wondering if it's kind of an edge case?
4 Replies
TechnoMage
TechnoMage2y ago
Do you need an API for your property relationship?
gdub01
gdub01OP2y ago
Sorry I'm not sure. My Property Looks like:
defmodule MyApp.Clients.Property do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

postgres do
table("client_properties")
repo(MyApp.Repo)
end

code_interface do
define_for(MyApp.Clients)
define(:by_client, args: [:client_id])
define(:get, args: [:id], get?: true)
end
... etc..
defmodule MyApp.Clients.Property do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

postgres do
table("client_properties")
repo(MyApp.Repo)
end

code_interface do
define_for(MyApp.Clients)
define(:by_client, args: [:client_id])
define(:get, args: [:id], get?: true)
end
... etc..
Like a normal resource. I just feel like I've defined everything the same way as other relationships like 'agency' and 'client' but the 'property' association fails to associate.
ZachDaniel
ZachDaniel2y ago
Can you make sure to update to the latest ash phoenix? We fixed a bug that this could be related to
gdub01
gdub01OP2y ago
Ah shoot this was my bad. I just renamed the fields and was still having the error. But then I just noticed I made a read action primary?: true that took an argument on the property resource. So I stopped making that primary and just now verified it's working. It needed a default read action that didn't take an argument which makes total sense, I just missed it. Sorry for the trouble!

Did you find this page helpful?