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

**URL:** <https://discuss.rubyonrails.org/t/rails-3-0-7-10-missing-scope-includes-breaks-the-chain/61469>\
**Category:** rubyonrails-talk\
**Created:** [November 1, 2011, 3:09pm UTC](https://discuss.rubyonrails.org/t/rails-3-0-7-10-missing-scope-includes-breaks-the-chain/61469 "2011-11-01T15:09:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Augusto\_Ruibal\_Shint](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Augusto\_Ruibal\_Shint](https://discuss.rubyonrails.org/u/Augusto_Ruibal_Shint)\
**Post date:** [November 1, 2011, 3:09pm UTC](https://discuss.rubyonrails.org/t/rails-3-0-7-10-missing-scope-includes-breaks-the-chain/61469/1 "2011-11-01T15:09:47Z")

</div>

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 &nbsp;&nbsp;has\_many :pictures

&nbsp;&nbsp;scope :active, where("expires\_on \> now()") &nbsp;&nbsp;scope :unsold, where("sold = 0") &nbsp;&nbsp;scope :approved, where("status = "approved") end

class Picture \< ActiveRecord::Base &nbsp;&nbsp;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.
