title: rails refactoring AR query
body: <p>I'm trying to refactor my scope, and my controller, but I feel it could be better. From the controllers perspective the new code is definitely better, but I think the <code>alltasks</code> scope and the <code>all_uncompleted_tasks_ordered_by_deadline</code> instance methods are kinda weird. Any ideas?</p>
  
  <p>user:</p>
  
  <pre><code>has_many :assigned_tasks, class_name: "Task", foreign_key: "assigner_id", dependent: :destroy
  has_many :executed_tasks, class_name: "Task", foreign_key: "executor_id", dependent: :destroy
  </code></pre>
  
  <p>task:</p>
  
  <pre><code>belongs_to :assigner, class_name: "User"
  belongs_to :executor, class_name: "User"
  scope :alltasks, -&gt; (u) { where('executor_id = ? OR assigner_id = ?', u.id, u.id) }
  scope :uncompleted, -&gt; { where(completed_at: nil) }
  </code></pre>
  
  <p>tasks controller</p>
  
  <pre><code>def index
    @tasks = Task.alltasks(current_user).uncompleted.includes(:executor, :executor_profile, :assigner, :assigner_profile).order("deadline DESC")
  end
  </code></pre>
  
  <p>NEW CODE:</p>
  
  <p>user.rb</p>
  
  <pre><code>def all_uncompleted_tasks_ordered_by_deadline
    Task.alltasks(self).uncompleted.includes(:executor, :executor_profile, :assigner, :assigner_profile).order("deadline DESC")
  end
  </code></pre>
  
  <p>tasks controller</p>
  
  <pre><code>def index
    @tasks = current_user.all_uncompleted_tasks_ordered_by_deadline
  end
  </code></pre>