【发布时间】:2020-10-15 17:23:45
【问题描述】:
我有 3 个简单的模型
class Tag < ApplicationRecord
belongs_to :category
belongs_to :course
end
class Course < ApplicationRecord
has_many :tags, dependent: :destroy
has_many :categories, through: :tags
end
class Category < ApplicationRecord
has_many :tags, dependent: :destroy
has_many :courses, through: :tags
end
给定一个类别为 string(例如“日语”),很容易找到 Category.find_by_title('Japanese').courses
如果类别在 数组 中,我很难进行查询,例如 ['Japanese', 'Language'] 需要返回标记为“Japanese”的课程 和“语言”
【问题讨论】:
标签: ruby-on-rails postgresql activerecord