我有以下型号:
class Task < ApplicationRecord
belongs_to :project
delegate :workspace, :to => :project, :allow_nil => true
belongs_to :importance
belongs_to :urgency
end
class Urgency < ApplicationRecord
has_many :tasks
end
class Importance < ApplicationRecord
has_many :tasks
end
我试图在视图中显示信息,该信息显示所有具有高紧急度和高重要性并按工作空间排序的任务的表。
在控制器中,我有以下代码:
@task_high_priority = Task.joins(:project => :workspace).order("workspaces.workspace_name").where(urgency_id: 1).where(importance_id: 1)
我想要做的是让查询中的where条件查看紧急度和重要性模型中的另一列(分别为urgency_value和importance_value)。
有办法做到这一点吗?
Task.joins(:project => :workspace)
.joins(:importance)
.joins(:urgency)
.where(urgency: {urgency_value: 'high'})
.where(importance: {importance_value: 'high'})
.order("workspaces.workspace_name")