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.
Rails 7.1 introduced the
query_constraints
qualifier that can be passed to the association definition.For example:
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