Guest User

Untitled

a guest
Mar 6th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Task.find(:all,
  2. :select => "distinct tasks.*",
  3. :joins => "inner join users on tasks.user_id = users.id inner join time_entries on time_entries.task_id = tasks.id",
  4. :conditions => ["users.id = ? and time_entries.task_date >= ? and time_entries.task_date <= ?",
  5. @user.id,
  6. '2007-06-18',
  7. '2007-06-24']).map{|t| t.project.name}
  8.  
  9. ## could that be rewritten like so?
  10.  
  11. class User
  12. has_many :time_entries, :through => :tasks
  13. end
  14.  
  15. @user.time_entries.find_all_by_task_date(Date(2007,6,18)..Date(2007,6,24)).map{|t| t.project.name }
Add Comment
Please, Sign In to add comment