Skip to content

feat: Add support for foreign_type qualifier on AssociationMatcher#1609

Merged
matsales28 merged 3 commits intomainfrom
add-support-for-foreign-type-qualifier
Mar 15, 2024
Merged

feat: Add support for foreign_type qualifier on AssociationMatcher#1609
matsales28 merged 3 commits intomainfrom
add-support-for-foreign-type-qualifier

Conversation

@matsales28
Copy link
Copy Markdown
Member

This PR adds Rubocop and code review adjustments on top of #1425:

Quoting @mswiszcz:

Allows to create tests checking set foreign_type

class Visitor < ActiveRecord::Base
  belongs_to :location, foreign_type: :facility_type, polymorphic: true
end

class Hotel < Location
  has_many :visitors, inverse_of: :location, foreign_type: :facility_type, as: :location
end

class PrisonCell < Location
  has_one :visitor, inverse_of: :location, foreign_type: :facility_type, as: :location
end
expect(Visitor.new).to belong_to(:location).with_foreign_type(:facility_type)
expect(Hotel.new).to have_many(:visitors).with_foreign_type(:facility_type)
expect(PrisonCell.new).to have_one(:visitor).with_foreign_type(:facility_type)

All credits go to @mswiszcz for this contribution.

@matsales28 matsales28 self-assigned this Feb 2, 2024
@matsales28 matsales28 requested a review from vsppedro as a code owner February 2, 2024 15:59
@matsales28 matsales28 merged commit efd1b39 into main Mar 15, 2024
@matsales28 matsales28 deleted the add-support-for-foreign-type-qualifier branch March 15, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants