Skip to content

Instantly share code, notes, and snippets.

@jlindley
Created June 12, 2009 18:49
Show Gist options
  • Save jlindley/128833 to your computer and use it in GitHub Desktop.
Save jlindley/128833 to your computer and use it in GitHub Desktop.
# has_many polymorphic, delays saving association until student is saved
june:dev> t = Tag.create
Tag Create (0.6ms) INSERT INTO "tags" ("updated_at", "created_at") VALUES('2009-06-12 18:45:29', '2009-06-12 18:45:29')
=> #<Tag id: 3, created_at: "2009-06-12 18:45:29", updated_at: "2009-06-12 18:45:29">
june:dev> s = Student.new
=> #<Student id: nil, created_at: nil, updated_at: nil>
june:dev> s.tags << t
=> [#<Tag id: 3, created_at: "2009-06-12 18:45:29", updated_at: "2009-06-12 18:45:29">]
june:dev> s.save
Student Create (0.4ms) INSERT INTO "students" ("updated_at", "created_at") VALUES('2009-06-12 18:45:43', '2009-06-12 18:45:43')
Tagging Create (0.1ms) INSERT INTO "taggings" ("updated_at", "tag_id", "taggable_type", "taggable_id", "created_at") VALUES('2009-06-12 18:45:43', 3, 'Student', 3, '2009-06-12 18:45:43')
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment