I have a company model with a key (domain). I have a contact model which also has a domain.
I have successfully setup a has_many relationship between these two.
has_many :contacts, class_name: 'Contact', primary_key: 'domain', foreign_key: 'domain'
Each contact has a
date field on it. I'd like a relationship which gets me the most recent contact (by
date) from the
Is this possible?
I'm aware I could do something like:
def most_recent_contact contacts.order('date desc null last').first end
Is this the best way? Is it the rails way? Open to suggestions.