Module: Mongoid::Denormalize::ClassMethods
- Defined in:
- lib/mongoid_denormalize.rb
Instance Method Summary collapse
-
#denormalize(*args) ⇒ Object
Set a field or a number of fields to denormalize.
- #is_denormalized? ⇒ Boolean
Instance Method Details
#denormalize(*args) ⇒ Object
Set a field or a number of fields to denormalize. Specify the associated object using the :from or :to options.
def Post
include Mongoid::Document
include Mongoid::Denormalize
referenced_in :user
references_many :comments
denormalize :name, :avatar, :from => :user
denormalize :created_at, :to => :comments
end
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid_denormalize.rb', line 30 def denormalize(*args) *fields, = args (self.denormalize_definitions ||= []) << { :fields => fields, :options => } # Define schema unless [:to] prefix = [:as] || [:from] fields.each do |name| field "#{prefix}_#{name}", :type => [:type] || String end end end |
#is_denormalized? ⇒ Boolean
44 45 46 |
# File 'lib/mongoid_denormalize.rb', line 44 def is_denormalized? true end |