Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created July 23, 2010 20:53
Show Gist options
  • Select an option

  • Save bernerdschaefer/488018 to your computer and use it in GitHub Desktop.

Select an option

Save bernerdschaefer/488018 to your computer and use it in GitHub Desktop.
require 'mongoid'
require 'rspec'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
config.autocreate_indexes = true
end
class TaskGroupWorker
include Mongoid::Document
embedded_in :task_group, :inverse_of => :task_group_workers
end
class TaskGroup
include Mongoid::Document
embeds_many :task_group_workers
collection.remove
end
task_group = TaskGroup.create
worker = TaskGroupWorker.new
task_group.task_group_workers << worker
worker.save
task_group.save
TaskGroup.first.task_group_workers.size.should == 1
@abuiles
Copy link

abuiles commented Jul 23, 2010

require 'mongoid'
require 'rspec'

Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
config.autocreate_indexes = true
end

class TaskGroupWorker
include Mongoid::Document
embedded_in :task_group, :inverse_of => :task_group_workers
end

class TaskGroup
include Mongoid::Document
embeds_many :task_group_workers
collection.remove
end

task_group = TaskGroup.create

worker = TaskGroupWorker.new
task_group.task_group_workers << worker
worker.save
task_group.save

TaskGroup.first.task_group_workers.size.should == 1
TaskGroupWorker.count.should ==1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment