Skip to content

Instantly share code, notes, and snippets.

@krishna-shilpakar
Created May 24, 2011 08:05
Show Gist options
  • Save krishna-shilpakar/988300 to your computer and use it in GitHub Desktop.
Save krishna-shilpakar/988300 to your computer and use it in GitHub Desktop.
Model inheritance or include
# Structure for inheritance
# app/models/parent/base.rb
class Parent::Base
include Mongoid::Document
end
# app/models/parent/first_child.rb
class FirstChild < Parent::Base
# fields needed for first child
end
app/models/parent/second_child.rb
class SecondChild < Parent::Base
# fields needed for second child
end
# Structure for Include/Extend
#
# app/models/parent.rb
class Parent
include Mongoid::Document
include Parent::FirstInclude
include Parent::SecondInclude
# fields
end
# app/models/parent/first_include.rb
module Parent::FirstChild
extends ActiveSupport::Concern
included do
end
module ClassMethods
end
module InstanceMethods
end
end
# similarly app/models/parent/second_include.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment