thoughtbot / shoulda-matchers

Simple one-liner tests for common Rails functionality
https://matchers.shoulda.io
MIT License
3.51k stars 912 forks source link

Add `query_constraints` qualifier to the association matcher. #1592

Closed matsales28 closed 9 months ago

matsales28 commented 10 months ago

Rails 7.1 introduced the query_constraints qualifier that can be passed to the association definition.

For example:

class Author < ApplicationRecord
  self.primary_key = [:first_name, :last_name]
  has_many :books, query_constraints: [:first_name, :last_name]
end

class Book < ApplicationRecord
  belongs_to :author, query_constraints: [:author_first_name, :author_last_name]
end

The idea here is to add the query_constraints qualifier to our association matchers.

https://edgeguides.rubyonrails.org/active_record_composite_primary_keys.html#associations-between-models-with-composite-primary-keys