graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

Fix many_to_many when one of the models has a prefix to the intersection model association

Open bguban opened this issue 1 year ago • 1 comments

Fix many_to_many when one of the models is under a namespace and has a prefix to the intersection model association.

class Hc::Validator < ApplicationRecord has_many :validator_universes has_many :universes, through: :validator_universes, inverse_of: :hc_validators end

class Hc::ValidatorResource < ApplicationResource many_to_many :universes, resource: UniverseResource, foreign_key: { hc_validator_universes: :validator_id } end

class Hc::ValidatorUniverse < ApplicationRecord belongs_to :validator belongs_to :universe end

class Universe < ApplicationRecord has_many :hc_validator_universes, class_name: 'Hc::ValidatorUniverse' has_many :hc_validators, class_name: 'Hc::Validator', through: :hc_validator_universes, source: :validator end

class UniverseResource < ApplicationResource many_to_many :hc_validators, resource: Hc::ValidatorResource, foreign_key: { validator_universes: :universe_id } end

bguban avatar Mar 13 '23 15:03 bguban

@bguban Mind adding a test for this? I'm not quite understanding the issue

jkeen avatar Feb 27 '24 19:02 jkeen