Created
April 10, 2011 10:17
-
-
Save utkarshkukreti/912218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[od]$ rails c | |
Loading development environment (Rails 3.0.6) | |
ruby-1.9.2-p180 :001 > Deparment.all | |
=> #<Mongoid::Criteria | |
selector: {}, | |
options: {}, | |
class: Deparment, | |
embedded: false> | |
ruby-1.9.2-p180 :002 > Deparment.all.entries | |
=> [] | |
ruby-1.9.2-p180 :003 > d = Deparment.create(:name => 'd1') | |
=> #<Deparment _id: 4da182c615c7cc695a000001, _type: nil, _id: BSON::ObjectId('4da182c615c7cc695a000001'), name: "d1", email: nil, operator_ids: []> | |
ruby-1.9.2-p180 :004 > d2 = Deparment.create(:name => 'd2') | |
=> #<Deparment _id: 4da182d115c7cc695a000002, _type: nil, _id: BSON::ObjectId('4da182d115c7cc695a000002'), name: "d2", email: nil, operator_ids: []> | |
ruby-1.9.2-p180 :005 > o1 = Operator.new(:name => 'o1') | |
=> #<Operator _id: 4da182e915c7cc695a000003, _type: nil, _id: BSON::ObjectId('4da182e915c7cc695a000003'), username: nil, name: "o1", email: nil, deparment_ids: []> | |
ruby-1.9.2-p180 :006 > o2 = Operator.new(:name => 'o2') | |
=> #<Operator _id: 4da182ee15c7cc695a000004, _type: nil, _id: BSON::ObjectId('4da182ee15c7cc695a000004'), username: nil, name: "o2", email: nil, deparment_ids: []> | |
ruby-1.9.2-p180 :007 > o1.save | |
=> true | |
ruby-1.9.2-p180 :008 > o2.save | |
=> true | |
ruby-1.9.2-p180 :009 > dd = Deparment.create(:operator_ids => [o1._id]) | |
=> #<Deparment _id: 4da1831515c7cc695a000005, _type: nil, _id: BSON::ObjectId('4da1831515c7cc695a000005'), name: nil, email: nil, operator_ids: [BSON::ObjectId('4da182e915c7cc695a000003')]> | |
ruby-1.9.2-p180 :010 > dd.operators | |
=> [#<Operator _id: 4da182e915c7cc695a000003, _type: nil, _id: BSON::ObjectId('4da182e915c7cc695a000003'), username: nil, name: "o1", email: nil, deparment_ids: []>] | |
ruby-1.9.2-p180 :011 > o1 | |
=> #<Operator _id: 4da182e915c7cc695a000003, _type: nil, _id: BSON::ObjectId('4da182e915c7cc695a000003'), username: nil, name: "o1", email: nil, deparment_ids: []> | |
ruby-1.9.2-p180 :012 > o1.save | |
=> true | |
ruby-1.9.2-p180 :013 > o1 | |
=> #<Operator _id: 4da182e915c7cc695a000003, _type: nil, _id: BSON::ObjectId('4da182e915c7cc695a000003'), username: nil, name: "o1", email: nil, deparment_ids: []> | |
ruby-1.9.2-p180 :014 > ddd = Deparment.create(:operators => [o1]) | |
=> #<Deparment _id: 4da1835415c7cc695a000006, _type: nil, _id: BSON::ObjectId('4da1835415c7cc695a000006'), name: nil, email: nil, operator_ids: [BSON::ObjectId('4da182e915c7cc695a000003')]> | |
ruby-1.9.2-p180 :015 > ddd.save | |
=> true | |
ruby-1.9.2-p180 :016 > o1 | |
=> #<Operator _id: 4da182e915c7cc695a000003, _type: nil, _id: BSON::ObjectId('4da182e915c7cc695a000003'), username: nil, name: "o1", email: nil, deparment_ids: [BSON::ObjectId('4da1835415c7cc695a000006')]> | |
ruby-1.9.2-p180 :017 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment