Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created September 19, 2013 00:24
Show Gist options
  • Save arthurnn/6617624 to your computer and use it in GitHub Desktop.
Save arthurnn/6617624 to your computer and use it in GitHub Desktop.
class Ship
include Mongoid::Document
has_one :vehicle
end
class Vehicle
include Mongoid::Document
belongs_to :ship
end
irb(main):009:0> s = Ship.new
=> #<Ship _id: 523a43d3d291624cb8000001, >
irb(main):010:0> s.vehicle = Vehicle.new
=> #<Vehicle _id: 523a43dbd291624cb8000002, ship_id: "523a43d3d291624cb8000001">
irb(main):011:0> s.save!
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (11.9979ms)
MOPED: 127.0.0.1:27017 INSERT database=echo_dev collection=ships documents=[{"_id"=>"523a43d3d291624cb8000001"}] flags=[] (0.1149ms)
=> true
irb(main):012:0> Vehicle.count
MOPED: 127.0.0.1:27017 COMMAND database=echo_dev command={:count=>"vehicles", :query=>{}} (7.9939ms)
=> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment