Module: SimplyStored::Couch::BelongsTo
Defined Under Namespace
Classes: Property
Instance Method Summary collapse
Methods included from Properties
Instance Method Details
#belongs_to(name, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/simply_stored/couch/belongs_to.rb', line 7 def belongs_to(name, = {}) check_existing_properties(name, SimplyStored::Couch::BelongsTo::Property) map_definition_without_deleted = " function(doc) { \n if (doc['ruby_class'] == '\#{self.to_s}' && doc['\#{name.to_s}_id'] != null) {\n if (doc['\#{soft_delete_attribute}'] && doc['\#{soft_delete_attribute}'] != null){\n // \"soft\" deleted\n }else{\n emit([doc.\#{name.to_s}_id, doc.created_at], 1);\n }\n }\n }\n eos\n \n reduce_definition = \"_sum\"\n \n view \"association_\#{self.name.underscore}_belongs_to_\#{name}\",\n :map => map_definition_without_deleted,\n :reduce => reduce_definition,\n :type => \"custom\",\n :include_docs => true\n \n map_definition_with_deleted = <<-eos\n function(doc) { \n if (doc['ruby_class'] == '\#{self.to_s}' && doc['\#{name.to_s}_id'] != null) {\n emit([doc.\#{name.to_s}_id, doc.created_at], 1);\n }\n }\n eos\n \n view \"association_\#{self.name.underscore}_belongs_to_\#{name}_with_deleted\",\n :map => map_definition_with_deleted,\n :reduce => reduce_definition,\n :type => \"custom\",\n :include_docs => true\n \n properties << SimplyStored::Couch::BelongsTo::Property.new(self, name, options)\nend\n" |