Skip to content

@JKring /mongo_test.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
MongoMapper Associations
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = "test_associations"
class Job
include MongoMapper::Document
belongs_to :invoice
before_save :do_something
def do_something
puts "saving a job"
end
end
class Invoice
include MongoMapper::Document
many :jobs
before_save :do_something
def do_something
puts "saving an invoice"
end
end
invoice = Invoice.new
10.times{ invoice.jobs << Job.create }
invoice.save
puts "==== Now we've created an Invoice with 10 Jobs ===="
puts "==== If we touch that Invoice, no problemo ===="
invoice = Invoice.first
invoice.save
puts "==== But if we touch that Invoice, and then touch all its Jobs, we have to save them all ===="
invoice.jobs.collect
invoice.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.