views:

28

answers:

1

I've got a single table inheritance structure in my application whereby Admins and Mods extends a User class. The table uses a discriminator value so each record has a type of either "admin" or "mod"

When it comes to finding a user (on login) I'd like to write the following:

current_user = User.find(params[:email => email])

However, this creates SQL which includes

SELECT ...... WHERE ("type" IN ('User') AND .....

This means that the record cannot be found. However if I type

current_user = Admin.find(params[:email => email])

I get the user (if they are an admin).

I've also tried the following to no avail since the 'type' IN ('User') is still created:

current_user = User.first(:email => email, :type => [Admin, Mod])

Thanks in advance for any help on this

A: 

I think it should be

current_user = User.first(:email => email, :type => ['Admin', 'Mod'])
Salil
Afraid not. The resulting sql looks something like: SELECT .....FROM "users" WHERE ("type" IN ('User') AND "type" IN ('Admin', 'Mod') AND "email" = .......
Gearóid