[Rails 3.0.7-10] Missing Scope + Includes breaks the Chain

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”)

class Picture < ActiveRecord::Base
belongs_to :ad

Now lets run some tests and try to explain myself:

=> “SELECT ads.* FROM ads WHERE (sold = 0) ORDER BY ads.created_at

All good.

=> NoMethodError: undefined method `there_is_no_scope’ for #<Class:

Awesome. Now comes the issue

=> 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.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs