I’m using Rails 4.2.7. I have this association …
class MyObject < ActiveRecord::Base
has_many :my_object_times
and
class MyObjectTime < ActiveRecord::Base
belongs_to :my_object
However I notice when I’m looking at a particular record in Rails, it is always giving me “0” for the size of my count when checking how many child items I have. For instance, when I execute this
puts "result name: #{result.name} id: #{result.id} MyObject times: #{result.my_object_times.size}"
I get
result name: 53rd Annual Lincoln Classic id: 79eaf6ea-284f-4421-82eb-39c3e9450f8e MyObject times: 0
But when I log in to my PostGres 9.5 database and run a query, I see plenty of child records …
myproject=> select count(*) FROM my_object_times where my_object_id = '79eaf6ea-284f-4421-82eb-39c3e9450f8e';
count
-------
490
How can I force an accurate count when checking how many children I have?