Scopes break db:schema:load

Hi, this is actually in response to the following thread... ...but Google Groups keeps giving me an error when I try to reply there.

I'm unable to run db:schema:load because it loads the Rails environment, the environment loads my models, and my models have scopes, which query the database. This is on Rails 3.0.5 and Ruby 1.8.7 on OSX.

Another developer and I have done some more digging on this and determined that it only happens on the one model in our app which has scopes and is subclassing another model with STI. It does stop happening if we remove all our observers and comment out calls to Devise in routes.rb, but that’s not really an option…

do you mind gist us the test case, or your bare model which would cost the error to occur?



So yeah, Devise is to blame here (it does the loading). Solution - define your scopes with blocks, i.e. change

class Post    scope :active, where(:active => true) end


class Post    scope :active, proc { where(:active => true) } end

Thanks! Is there any workaround for when this happens due to default_scope? I see that it doesn’t support blocks yet.

Unfortunately - no, and if you want the whole story - check out this one #1812 default_scope can't take procs - Ruby on Rails - rails