Hi Scott,

  I've seen some things like this before, in different scenarios, and have a
couple questions to see if I can hone in on what might be going on:

  First, to get my grounding on your environment, What version of rails are
you using?  And are you using any sorts of object deletion related plugins
like acts_as_paranoid?

  Second, can you look at your logs when you run agency.donors.size and see
if it is doing a mysql query?  If not, it may just be looking at the counter
cache...

Another thing to look at is something like Donor.find_all_by_agency_id(
agency.id), and see if that turns anything up... If so, it may be there is
something broken in the associations...

  Let me know, thanks

-Kevin

On Wed, Oct 13, 2010 at 5:19 PM, Scott Olmsted <[email protected]> wrote:

> A project has a MySQL database. There are Agencies, each has_many
> Donors, each Donor belongs_to :agency, :counter_cache => true.
>
> On my development machine the donors_count field in Agency looks good,
> and I wrote and tested a rake task to set it properly for all
> Agencies.
>
> On production the count for one Agency was set by the rake task to 3,
> but I can't see the records in the console:
>
> >> agency=Agency.find(27)
> => #<Agency id: 27, name: ... , donors_count: 3>
> >> agency.donors.size
> => 3
> >> agency.donors
> => []
>
> Where are the donors that it counted? My GUI tool for MySQL in Ubuntu,
> HeidiSQL, shows me that they're there. If I search for one I know is
> there on production:
>
> >> donor=Donor.find(18706)
> ActiveRecord::RecordNotFound: Couldn't find Donor with ID=18706
>        from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/
> activerecord-2.3.5/lib/active_record/base.rb:1586:in `find_one'
>        ....
>
> where I can find that same record on my machine fine. And on
> production finding a similar record belonging to a different Agency
> works fine:
>
> >> donor=Donor.find(18455)
> => #<Donor id: 18455, internal_id: "May2490", ...
>
> Any ideas? Is the production database corrupted?
>
> Thanks,
>
> Scott
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to