我有两个模型,书籍和目录。
class Book < ActiveRecord::Base
has_and_belongs_to_many :catalogs
end
class Catalog < ActiveRecord::Base
has_and_belongs_to_many :books
end
我需要查找仅属于特定目录列表的书籍。我努力了,
DEFAULT_CATALOGS = ["A","B"]
Book.joins(:catalogs).where("catalogname = ?",DEFAULT_CATALOGS)
但我得到一个异常 Mysql2::Error: Operand should contain 1 column(s):