Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not compute table names for abstract classes #2679

Merged
merged 1 commit into from Aug 24, 2011

Conversation

amatsuda
Copy link
Member

I found a trivial inconsistency on AR table_name computing behavior.

While there are an abstract_class model and its child:

class User < ActiveRecord::Base
  self.abstract_class = true
end

class Admin < User
end

The child's table_name changes depending on whether the abstract model's table_name were called or not.

User.table_name
=> "users"
User.scoped.to_sql
=> SELECT "users".* FROM "users"
Admin.table_name
=> "users"
Admin.scoped.to_sql
=> SELECT "users".* FROM "users"

Admin.table_name
=> "admins"
Admin.scoped.to_sql
=> SELECT "admins".* FROM "admins"

This doesn't matter for normal use, but sometimes causes weird errors, for example, when dealing with an AR extension plugin that scans through descendants of AR::Base on Railtie hook.

Here's a patch that makes abstract models always skip compute_table_name.

tenderlove added a commit that referenced this pull request Aug 24, 2011
do not compute table names for abstract classes
@tenderlove tenderlove merged commit 5345958 into rails:master Aug 24, 2011
@amatsuda
Copy link
Member Author

Thank you @tenderlove!
Can you please backport this to 3-1-stable?

@tenderlove
Copy link
Member

@amatsuda done!

@amatsuda
Copy link
Member Author

@tenderlove Thank you!

@route
Copy link
Contributor

route commented Oct 11, 2011

What about scopes?

class User < ActiveRecord::Base
  self.abstract_class = true
  scope :something, where(:name => 'something')
end

class Admin < User
end

Admin.something.to_sql => "SELECT \"admins\".* FROM \"admins\"  WHERE \"\".\"name\" = 'something'"

And we have missed table name in where statment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants