I have a Staff model, which has many staff_orders
class Staff < Ressource
has_many :staff_orders
The staff_orders contain a from_date and a to_date. During this time the staff member is occupied.
I want to create a dropdown list of staff members, where behind each staff_member the dates are show, when he is occupied: "Ralph Allen (Nov 1st- Nov 2nd, Nov 4th - Nov 5th)"
In this case the eager loading works perfectly. I need to use the LEFT JOIN, as I want to list all Staff member, no matter weather they are occupied by staff_orders or not.
@staff_collection = Staff.joins("LEFT JOIN staff_orders ON
staffs.id=staff_orders.staff_id").
collect{ |x| [x.long_name, x.id] }
But now comes the tricky part. Now I only want to add the occupied information only of a certain time span (e.g. this week) behind the name of the Staff member. For example: "Ralph Allen (Nov 4th - Nov 5th)"
@staff_collection = Staff.joins("LEFT JOIN staff_orders ON
ressources.id=staff_orders.staff_id").
collect{ |x| [x.long_name_occupied(@from_date,@to_date), x.id] }
I do this by calling the name method with the filtering dates as parameters. Now it doesn't perform the eager loading anymore. Any idea?