Ruby on Rails Tuesday, November 1, 2011

Hello guys, found this issue in version 3.0.7, just working in the
same site with 3.0.10 and the same issue pops out.

Lets say we have a Classified site, so we have ads and pictures:

class Ad < ActiveRecord::Base
has_many :pictures

scope :active, where("expires_on > now()")
scope :unsold, where("sold = 0")
scope :approved, where("status = "approved")
end

class Picture < ActiveRecord::Base
belongs_to :ad
end

Now lets run some tests and try to explain myself:

> Ad.unsolds.to_sql
=> "SELECT `ads`.* FROM `ads` WHERE (sold = 0) ORDER BY ads.created_at
desc"

All good.

> Ad.there_is_no_scope.unsolds.to_sql
=> NoMethodError: undefined method `there_is_no_scope' for #<Class:
0xa41b7d4>

Awesome. Now comes the issue

> Ad.includes(:picture).there_is_no_scope.unsolds.to_sql
=> NoMethodError:

I have 1.6M of records in my ads table, obviously I noted some kind of
hanging, the problem was,
Ad.includes(:picture).there_is_no_scope.unsolds.to_sql raise the
NoMethodError but also executes the query defined before the missing
scope, in this case "select * from ads".

I can create an example application if this is not understandable.

Just want you guys to know about this issue.

Thanks.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment