Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bguban
Copy link

@bguban bguban commented Mar 13, 2023

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 and others added 2 commits March 13, 2023 17:18
…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
@jkeen
Copy link
Collaborator

jkeen commented Feb 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants