How to check if an ActiveRecord association was already eager loaded
if you need to know whether to use a pre-laoded collection using eager loading or fech the collections, you can always call loaded? method:
if user.contact_phones.loaded?
user.contact_phones.detect? {|phone| phone.primary }
else
user.contact_phones.find_by(primary: true)
end