0

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

Gerard
  • 4,818
  • 5
  • 51
  • 80

1 Answers1

0

I think it should be

current_user = User.first(:email => email, :type => ['Admin', 'Mod'])
Salil
  • 46,566
  • 21
  • 122
  • 156
  • Afraid not. The resulting sql looks something like: SELECT .....FROM "users" WHERE ("type" IN ('User') AND "type" IN ('Admin', 'Mod') AND "email" = ....... – Gerard Jun 02 '10 at 13:39