jlindley (owner)

Revisions

  • d572b3 jlindley Fri Jun 12 11:49:08 -0700 2009
gist: 128833 Download_button fork
public
Public Clone URL: git://gist.github.com/128833.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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