Ash FrameworkAF
Ash Framework3y ago
6 replies
gdub01

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"
    },


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


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


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?
Was this page helpful?