我有一个简单的has_many:通过排列,如下图
# employee.rb
class Employee < ActiveRecord::Base
has_many :group_assignments
has_many :groups, through: :group_assignments
# ...
end
# group.rb
class Group < ActiveRecord::Base
has_many :group_assignments
has_many :employees, through: :group_assignments
# ...
end
# group_assignment.rb
class GroupAssignment < ActiveRecord::Base
belongs_to :employee
belongs_to :group
end
我有一份员工名单。对于该列表,我想获取包含该列表中至少一名员工的每个组。我将如何以一种不是非常低效的方式完成此任务?我对 Rails 很陌生,对 SQL 也很陌生,我很茫然。我在开发中使用 SQLite,在生产中使用 PostgreSQL。