ruby - Single-table inheritance using a datetime column -
I have a user class that handles both registered and unregistered users in our database. I have maintained the user and registered users of subclasses I'm leaning towards using STI, but I think it's adding some repetition to my code where it's not really necessary.
I am currently planning for the ad "Type" and "Registered" column. In fact everyone needs to be present whether or not they are presently included on the "registered_at" users.
User t.string "type" t.datetime "register_at"
This rail does not fit the STI conference, but it seems like something Reduce the repetition which is otherwise unnecessary. Does this make sense and how do I create it in my user model?
Why not only use scope? Scope: unregistered, lambda {where (: registered_it => zero)} scope: registered, lambda {where ("registered_t is not empty")}
and like them:
User.registered.first
Edit
Get your Subclasses from User
and you can use default_scope
, eg:
class unregisteredUser & lt; User default_scope {uncontrolled} # callback, etc. End
Comments
Post a Comment