From 09aa8c443d8ffd578b0e8eddb82c7de367dba97a Mon Sep 17 00:00:00 2001 From: Bogdan Guban Date: Mon, 13 Mar 2023 17:18:09 +0200 Subject: [PATCH] fix many_to_many when one of the models is under a namespace and has a prefix to the intersection model. 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 --- lib/graphiti/adapters/active_record/many_to_many_sideload.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/graphiti/adapters/active_record/many_to_many_sideload.rb b/lib/graphiti/adapters/active_record/many_to_many_sideload.rb index 803c64cf..ccdbaf18 100644 --- a/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +++ b/lib/graphiti/adapters/active_record/many_to_many_sideload.rb @@ -1,7 +1,6 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload::ManyToMany def through_table_name - @through_table_name ||= parent_resource_class.model - .reflections[through.to_s].klass.table_name + @through_table_name ||= resource_class.model.reflections[through.to_s].klass.table_name end def through_relationship_name