Probably a confusing title, but not sure how else to express it. An example should be clearer. I have many different models that have the same attributes. Therefore, in each model, I must specify the same attributes, and THEN the attributes specific to this particular model.
Is it possible to create some class that lists these basic attributes and then inherit from this class without using single-page inheritance? Because if I put all the common attributes and included Mongoid in one model and inherited from this base model in other models, then the STI will be enforced and all my models will be saved in one mongodb collection, differentiated by the "_type" field.
This is what I have:
class Model_1 include Mongoid::Document field :uuid, :type => String field :process_date, :type => String ... end class Model_2 include Mongoid::Document field :uuid, :type => String field :process_date, :type => String ... end
But this is the functionality that I use:
class Base_model field :uuid, :type => String field :process_date, :type => String end class Model_1 < Base_model # To ensure STI is not enforced include Mongoid::Document # Attribute list inherited from Base_model end
The problem is that if you do not have "enable Mongoid :: Document" in Base_model, then this base model does not know about the functionality of "field ...". But if you include mongoid in the base model and inherit it, the STI will be enforced.
I canβt do an STI for this specific situation, but itβs a code code to have several models, all with the same list of attributes indicated over and over (the number of models is growing and each share is about 15-20 attributes, so anytime when I have to change the name of the model, he takes a lot of effort to change it everywhere ...).
mongodb ruby-on-rails-3 mongoid sti
Dan l
source share