I imported a db schema and its content from a legacy site into a Rails project.
I have DVDs and votes. Votes are simply an integer field in Dvd model like Dvd.votes:integer=10.
Since I can also associate new votes to users easily in Rails, I created a new Vote model that belongs to Dvd and User models.
My situation is that now when calling Dvd.first.votes I get an empty array [] since there’s no data yet on the Vote model but the votes_count still has the imported counts.
(I also renamed the Dvd.votes field to Dvd.votes_count after adding the Vote model and added belongs_to :dvd, :counter_cache => true on Vote model.)
I’m not sure what would be the ideal solution to this problem. Should I call votes by simply querying Dvd.votes_count or there’s a better way to do it?
Sorry, it might be not an answer for your question, but instead of creating your own solution I recommend to use gem: https://github.com/bouchard/thumbs_up
which already optimized. In your situation it may save a lot of time.
So you need to install gem and then import existing votes to it.