graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
960 stars 138 forks source link

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

Open bguban opened 1 year ago

bguban commented 1 year ago

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

jkeen commented 4 months ago

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