User (with id, first_name, ....)
Assignment (with id, name, start_date, finish_date,....)
AssignmentUser(with assignment_id, user_id, flag_status)
The flag_status is a boolean that says if a user is still or not in an
Let's say user1 applies for assignment1, assignment2, assignment3 as
user1 assignment1 11-11-11 11-12-11 false
user1 assignment2 01-10-11 01-02-12 true
user1 assignment3 01-01-12 01-03-12 true
Let's say I want to search TODAY the closest start_date of an user's
I've done this in my User model:
self.assignments.where("date < ?", Date.today).max.try(:date)
self.id).flag_status if self.last_date.present?
And in my view for each user:
User.all.each do |u|
<td> u.first_name </td>
<td> u.last_email </td>
<td> u.last_status </td>
It works well but, in my log I see 3 queries for each user (as
expected). So my question is: how can I avoid these multiple queries?
Thanks in advance
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.