Rails unidirectional inheritance / subclass search in parent

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

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

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

I tried the following in my pointer controller, but no matter what I set for the type, it returns all users regardless of type.

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

How to find out how this condition works?

Thank!

+3
source share
2 answers

Ok, got it!

The application uses lib for standard controller methods (similar to resource_controller), and I incorrectly rewrote the index method in the user controller.

Thanks for helping Achim!

0
source

I do not know how the 'type' attribute is populated. But if the type is a database column, you can filter it with the appropriate SQL expression:

User.find(:all, :conditions => [ " type=null or type='' "])

Or do you mean the class function? as far as I know, the "type" is out of date. IRB Status: Warning: Object Type # Deprecated; use class Object #

+1
source

Source: https://habr.com/ru/post/1738969/


All Articles