Ash FrameworkAF
Ash Framework3y ago
31 replies
frankdugan3

Many to Many Error

Given these relationships:

# Capability
relationships do
  many_to_many :steps, Hsm.Ash.MCP.Step do
    through Hsm.Ash.MCP.StepCapability
    source_attribute_on_join_resource :capability_id
    destination_attribute_on_join_resource :step_id
  end
end

# Step
relationships do
  many_to_many :capabilities, Hsm.Ash.Workcenters.Capability do
    through Hsm.Ash.MCP.StepCapability
    source_attribute_on_join_resource :step_id
    destination_attribute_on_join_resource :capability_id
  end
end

# StepCapability
relationships do
  belongs_to :capability, Hsm.Ash.Workcenters.Capability,
    allow_nil?: false,
    api: Hsm.Ash.Workcenters
  belongs_to :step, Hsm.Ash.MCP.Step, allow_nil?: false, api: Hsm.Ash.MCP
end


All of them are in the same API and Registry.

I'm getting an error that I don't quite understand (join_relationship_name???):

** (EXIT from #PID<0.96.0>) an exception was raised:
    ** (RuntimeError) Resource `Hsm.Ash.MCP.StepCapability` is not in registry `Hsm.Ash.Workcenters.Registry` for autogenerated join relationship: `:steps_join_assoc`

Relationship was generated by the `many_to_many` relationship `:steps`

If the `through` resource `Hsm.Ash.MCP.StepCapability` is not accepted by the same
api as the destination resource `Hsm.Ash.MCP.Step`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:

    has_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
      # configure the relationship attributes
      ...
    end

You can use a name other than `:steps_join_assoc`, but if you do, make sure to
add that to `:steps`, i.e

    many_to_many :steps_join_assoc, Hsm.Ash.MCP.StepCapability do
      ...
      join_relationship_name :your_new_name
    end

        (ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:43: anonymous fn/5 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
        (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:16: anonymous fn/4 in Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
        (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (ash 2.9.5) lib/ash/registry/extensions/resource_validations/verifiers/validate_related_resource_inclusion.ex:15: Ash.Registry.ResourceValidations.Verifiers.ValidateRelatedResourceInclusion.verify/1
        lib/hsm/ash/workcenters/registry.ex:1: anonymous fn/1 in Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1
        (elixir 1.14.4) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
        lib/hsm/ash/workcenters/registry.ex:1: Hsm.Ash.Workcenters.Registry.__verify_ash_dsl__/1

I'm probably missing something obvious, but I can't spot it.
Was this page helpful?