I have a user model and another model that tells me the time they "checked-in" to work.
User
- id
- name
Checkins
- user_id
- timestamps
So in my User model I have this:
class User < ApplicationRecord
has_many :checkins
end
What I want to do is on a page display a list of users, and IF they have a checkin for the current day then the 'checkin' association should be present, otherwise null.
@users = User.find_todays_checkin()
So I have to basically perform an outer join I guess?
select *
from users u
outer join checkins c on u.id = c.user_id
where c.created_at = '2017-10-21'
A user may or may not have a checkin for the current day, if they do, the checkin association should be non-nil, otherwise nil.
How can I do this query using active record?