Rails single table inheritance/subclass find condition in parent

Posted by slythic on Stack Overflow See other posts from Stack Overflow or by slythic
Published on 2010-03-29T14:02:39Z Indexed on 2010/03/29 14:23 UTC
Read the original article Hit count: 547

Hi all,

I have a table called Users (class User < ActiveRecord::Base) and a subclass/STI of it for Clients (class Client < User).

Client "filtering" works as expected, in other words Client.find(:all) works to find all the clients.

However, for users I need to filter the result to only find users that are NOT clients (where type is null or blank).

I've tried the following in my index controller but no matter what I put for the type it returns all users regardless of type.

User.find(:all, :conditions => { :type => nil }, :order => 'name')

Any clue on how to get this condition to work?

Thanks!

© Stack Overflow or respective owner

Related posts about rails

Related posts about subclass