Anonymous scopes hitting database

From what I can understand, I should be able to treat an anonymous
scope as an intermediary object with which to build queries on the
fly.

Following the procedure in Railscast episode 112 (http://
railscasts.com/episodes/112), I try the following (in script/console):

a = Production.scoped({})

Hitting return results in a call to the database and all (hundreds of
thousands) records returned.

Is this the expected behavior?

I was hoping to use this to add various scopes according to the search
parameters requested, but I can’t afford to do full table scans on
each step.

What could I be doing wrong?

Thanks for any ideas,

John

On Aug 28, 3:52 am, JDevine [email protected] wrote:

thousands) records returned.

Is this the expected behavior?

I was hoping to use this to add various scopes according to the search
parameters requested, but I can’t afford to do full table scans on
each step.

What could I be doing wrong?

The console is fooling you: it’s trying to display a, and trying to
display it causes the scope to be loaded.
if you did a - Production.scoped({}); false
(so what the console displays is just false) then you should be ok

Fred

That’s very good news. I’m just not up for a dive into the internals
today.

Thanks Frederick!

On Aug 28, 2:48 am, Frederick C. [email protected]

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