Rails filtering records in many to many relationship
问题 I have many to many relationship for books and authors like: class Book < ApplicationRecord has_many :books_authors, inverse_of: :author, dependent: :destroy has_many :authors, through: :books_authors end class Author < ApplicationRecord has_many :books_authors, dependent: :destroy has_many :books, through: :books_authors end class AuthorsBook < ApplicationRecord belongs_to :author belongs_to :book end Now to get all the Books with Authors of ids: 1 and 3 The query is like : Book.joins(