I\'m struggling how to have Ruby on Rails do this query right... in short: to join on a has_many relation but only via the most recent record in that r
has_many
+1 to @max's answer.
An alternative though is to add a start_date and end_date attribute to Employment. To get active employees, you can do
start_date
end_date
Employment
Employee .joins(:employments) .where('end_date is NULL OR ? BETWEEN start_date AND end_date', Date.today)