[BUG?] ar inheritance

searched the tracker... but didn't manage to find something like this:

>> User.table_name
=> "users"

>> User
=> User(id: integer, email: string, encrypted_password: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime)

>> PendingUser.table_name
=> "pending_users"

>> PendingUser
=> PendingUser(id: integer, email: string, encrypted_password: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime)

>> PendingUser.create! :email => 'ara.t.howard@gmail.com', :password => 'foobar'
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: pending_users.email: SELECT * FROM users WHERE (LOWER(pending_users.email) = 'ara.t.howard@gmail.com') LIMIT 1

>> PendingUser.ancestors.map(&:name).first(3)
=> ["PendingUser", "User", "ActiveRecord::Base"]

>> puts IO.read('app/models/pending_user.rb')
class PendingUser < User
   set_table_name 'pending_users'
end

have i overlooked? Rails 2.0.1...

a @ http://drawohara.com/

searched the tracker... but didn't manage to find something like this:

>> User.table_name
=> "users"

>> User
=> User(id: integer, email: string, encrypted_password: string,
created_at: datetime, updated_at: datetime, remember_token: string,
remember_token_expires_at: datetime)

>> PendingUser.table_name
=> "pending_users"

>> PendingUser
=> PendingUser(id: integer, email: string, encrypted_password:
string, created_at: datetime, updated_at: datetime, remember_token:
string, remember_token_expires_at: datetime)

>> PendingUser.create! :email => 'ara.t.howard@gmail.com', :password
=> 'foobar'
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such
column: pending_users.email: SELECT * FROM users WHERE (LOWER
(pending_users.email) = 'ara.t.howard@gmail.com') LIMIT 1

>> PendingUser.ancestors.map(&:name).first(3)
=> ["PendingUser", "User", "ActiveRecord::Base"]

>> puts IO.read('app/models/pending_user.rb')
class PendingUser < User
   set_table_name 'pending_users'
end

have i overlooked? Rails 2.0.1...

AR only support single table inheritance, so what you're trying to do
won't work. set_table_name should probably raise an exception to
prevent you getting surprised like that though.

seriously? the docs say:

"If you don‘t have a type column defined in your table, single-table inheritance won‘t be triggered. In that case, it‘ll work just like normal subclasses with no special magic for differentiating between them or reloading the right type with find."

and, of course, i have no type field... and, in the source

ar/base.rb

1060 # True if this isn't a concrete subclass needing a STI type condition.
1061 def descends_from_active_record?
1062 if superclass.abstract_class?
1063 superclass.descends_from_active_record?
1064 else
1065 superclass == Base || !columns_hash.include?(inheritance_column)
1066 end
1067 end

which i was reading to be inline with the docs. also the code i posted has worked with previous versions of rails just fine...

of course you would know! :wink:

did i just get lucky before?

kind regards.

a @ http://codeforpeople.com/

which i was reading to be inline with the docs. also the code i
posted has worked with previous versions of rails just fine...

of course you would know! :wink:

I *should* know, very different apparently :slight_smile:

did i just get lucky before?

I still am surprised it did work before, but assuming it did, and the
fix is simple, I'm happy to take a patch :slight_smile:

I *should* know, very different apparently :slight_smile:

did i just get lucky before?

lol!

I still am surprised it did work before, but assuming it did, and the
fix is simple, I'm happy to take a patch :slight_smile:

well i may be on thin ice - not knowing what's really intended in the source - but, unless someone chimes in that it really is *not* supposed to work i'll have a go.

cheers.

a @ http://codeforpeople.com/

Considering that the docs say it should work, and the "least surprise" way
would be to allow subclassing to work normally, I think a patch would be
valuable.

- Matt

Considering that the docs say it should work, and the "least surprise" way
would be to allow subclassing to work normally, I think a patch would be
valuable.

Absolutely.