Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

can't have a column called scope #8850

Closed
robmathews opened this Issue · 11 comments

6 participants

@robmathews

Create a model Foo with a column called scope. Then try to find all the matching Foo by scope, like so:

Foo.where(:scope=>1).first

You get this traceback:

[7] pry(main)> Foo.where(:scope=>1).first
SystemStackError: stack level too deep

This on rails 3.2.10 and ruby 1.9.3p327

I can provide more details if you want, but it seems pretty straightforward ...

@seanmccann

scope is a reserved word, therefore using it as a column name will not work.

@robmathews

Well, scope isn't on this list as a reserved word for columns. It says to avoid using it as an association name, that is all. And I can't find any more up to date list of reserved words.

@steveklabnik
Collaborator

Yes, it'd be impossible to keep the list up-to-date.

@robmathews

Impossible to keep the list of up to date? Really?

@tehgeekmeister

That seems like a potential usability nightmare, if that's actually true. I don't have much stake in the original issue here, but just keeping a textual list somewhere seems pretty reasonable.

On the other hand, I admit that in a few years of rails work, I've never been bit by this....

If not a list somewhere, how should new rails devs know what column names to avoid? Has to be something you've got some input on from personal experience, @steveklabnik.

@amatsuda
Collaborator

@robmathews Are you sure you can reproduce the situation with a vanilla app?
I tried in both master and newest 3.2 but Foo.where(:scope=>1).first just works fine for me.
I guess one of the gems you're bundling is actually causing your "stack level too deep".

@robmathews
@robmathews
@fxn
Owner

AR models inherit from AR::Base, inherited methods are not reserved words, we are talking standard OOP.

@robmathews
@fxn
Owner

Yes, because in AR a column definition triggers the definition of a method with the same name.

That's why you can have a blank User class and still be able to write user.name. There, name is a method that has been defined on the fly.

So all ends in the same place, you need to define class interfaces that play well with the methods they inherit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.