Skip to content

Instantly share code, notes, and snippets.

@raine
Created October 16, 2011 12:47
Show Gist options
  • Select an option

  • Save raine/1290839 to your computer and use it in GitHub Desktop.

Select an option

Save raine/1290839 to your computer and use it in GitHub Desktop.
Loading development environment (Rails 3.1.0)
ruby-1.9.2-p180 :001 >
ruby-1.9.2-p180 :002 >
ruby-1.9.2-p180 :003 > HeadType.create
SQL (12.9ms) INSERT INTO "head_types" ("created_at", "updated_at") VALUES (?, ?) [["created_at", Sun, 16 Oct 2011 12:45:08 UTC +00:00], ["updated_at", Sun, 16 Oct 2011 12:45:08 UTC +00:00]]
=> #<HeadType id: 1, created_at: "2011-10-16 12:45:08", updated_at: "2011-10-16 12:45:08">
ruby-1.9.2-p180 :004 > HeadType.create
SQL (0.3ms) INSERT INTO "head_types" ("created_at", "updated_at") VALUES (?, ?) [["created_at", Sun, 16 Oct 2011 12:45:10 UTC +00:00], ["updated_at", Sun, 16 Oct 2011 12:45:10 UTC +00:00]]
=> #<HeadType id: 2, created_at: "2011-10-16 12:45:10", updated_at: "2011-10-16 12:45:10">
ruby-1.9.2-p180 :005 > p = PressureVessel.create
SQL (0.5ms) INSERT INTO "pressure_vessels" ("created_at", "head_one_id", "head_two_id", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sun, 16 Oct 2011 12:45:43 UTC +00:00], ["head_one_id", nil], ["head_two_id", nil], ["updated_at", Sun, 16 Oct 2011 12:45:43 UTC +00:00]]
=> #<PressureVessel id: 1, head_one_id: nil, head_two_id: nil, created_at: "2011-10-16 12:45:43", updated_at: "2011-10-16 12:45:43">
ruby-1.9.2-p180 :006 > p.head_one_
p.head_one_id p.head_one_id_before_type_cast p.head_one_id_was p.head_one_type=
p.head_one_id= p.head_one_id_change p.head_one_id_will_change! p.head_one_type_loaded?
p.head_one_id? p.head_one_id_changed? p.head_one_type
ruby-1.9.2-p180 :006 > p.head_one_type = HeadType.find(1)
HeadType Load (0.2ms) SELECT "head_types".* FROM "head_types" WHERE "head_types"."id" = ? LIMIT 1 [["id", 1]]
=> #<HeadType id: 1, created_at: "2011-10-16 12:45:08", updated_at: "2011-10-16 12:45:08">
ruby-1.9.2-p180 :007 > p.head_two_type = HeadType.find(2)
HeadType Load (0.1ms) SELECT "head_types".* FROM "head_types" WHERE "head_types"."id" = ? LIMIT 1 [["id", 2]]
=> #<HeadType id: 2, created_at: "2011-10-16 12:45:10", updated_at: "2011-10-16 12:45:10">
ruby-1.9.2-p180 :008 > p.save
(0.3ms) UPDATE "pressure_vessels" SET "head_one_id" = 1, "head_two_id" = 2, "updated_at" = '2011-10-16 12:46:24.063439' WHERE "pressure_vessels"."id" = 1
=> true
ruby-1.9.2-p180 :010 > HeadType.first.head_one_pressure_vessels
HeadType Load (0.1ms) SELECT "head_types".* FROM "head_types" LIMIT 1
PressureVessel Load (0.1ms) SELECT "pressure_vessels".* FROM "pressure_vessels" WHERE "pressure_vessels"."head_one_id" = 1
=> [#<PressureVessel id: 1, head_one_id: 1, head_two_id: 2, created_at: "2011-10-16 12:45:43", updated_at: "2011-10-16 12:46:24">]
ruby-1.9.2-p180 :011 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment