examples/simple_document.rb in mongo_doc-0.3.2 vs examples/simple_document.rb in mongo_doc-0.4.0

- old
+ new

@@ -1,23 +1,23 @@ require 'mongo_doc' class Address include MongoDoc::Document - key :street - key :city - key :state - key :zip_code - key :phone_number + attr_accessor :street + attr_accessor :city + attr_accessor :state + attr_accessor :zip_code + attr_accessor :phone_number end class Contact include MongoDoc::Document - key :name - key :interests - has_many :addresses + attr_accessor :name + attr_accessor :interests + embed_many :addresses scope :in_state, lambda {|state| where('addresses.state' => state)} end Contact.collection.drop @@ -30,12 +30,12 @@ Contact.find_all.each {|c| puts c.name} puts contact.to_param puts Contact.find_one(contact.to_param).addresses.first.street Contact.find(contact.to_param).each {|c| puts c.name} -hashrocket = Contact.in_state('FL').find {|contact| contact.name == 'Hashrocket'} +hashrocket_in_fl = Contact.in_state('FL').where(:name => /rocket/) -hashrocket_address = hashrocket.addresses.first +hashrocket_address = hashrocket_in_fl.first.addresses.first hashrocket_address.update_attributes(:street => '320 First Street North, #712') puts Contact.where(:name => 'Hashrocket').first.addresses.first.street # Criteria behave like new AR3 AREL queries