On 23 December 2010 20:21, Gerardo <[email protected]> wrote:
> Hi,
> My application is running over ubuntu 10, ruby 1.9.2, rails 3.0.3 and
> passenger 3.0.2 + nginx.
>
> This application has several polymorphic associations and the problem
> is that when the associations are called it  randomly returns either
> the related object or an ActiveRecord::Relation object.
>
> Has anybody had a similar problem or is this a known issue?
>
> Basically the Model looks like this:
> class Blahblah < ActiveRecord::Base
>  belongs_to :data_object, :polymorphic => true
> end
>
> When I call data_object.id, sometimes I'll get the following error:
> "undefined method 'id' for ActiveRecord::Relation"
> other times, the association works fine

Are you sure that data_object is always a single object and not
sometimes an array (even though containing possibly only one record).
I have seen this when I have used a named scope that I know will
return a single record, but in fact it is an array containing one
element.

Whether you think that may be it or not, if it is a particular line or
a few places in the code that sometimes fails you could catch the
exception there and log the contents of data_object for analysis.  Or
if you can make it fail in development use ruby-debug to break into
the exception handler.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to