Reputation: 61
I'm seeing an interesting behavior and would like some insight.
I have two models: Person & User. User inherits from Person. There is no users db table, just people.
When I search for a user I've created using Person's find model, I'm expecting to see an object of type person returned. But its type is user.
@person = Person.find(params[:id])
@person.class
# outputs 'User'
Can someone please explain why it wouldn't return a person object.
Upvotes: 1
Views: 267
Reputation: 72514
That is the desired behaviour. The type
column of the found person row contains the value "User". Because of that the returned type is User
, too.
Remember that User
also is a Person
, so you can treat any User
instance like it was a Person
instance.
Upvotes: 3