Skip to content

Instantly share code, notes, and snippets.

@neaf
Created March 16, 2009 19:02
Show Gist options
  • Save neaf/80010 to your computer and use it in GitHub Desktop.
Save neaf/80010 to your computer and use it in GitHub Desktop.
after_create do
revision = WriteboardRevision.create(:content => self.content, :user_id => self.user_id, :writeboard_id => self.id)
self.update(:current_revision => revision.id)
end
--------------------
>> w = Writeboard.new
=> #<Writeboard @values={}>
>> w.title ="Title"
=> "Title"
>> w.content ="Content"
=> "Content"
>> w.user = User.first
~ SELECT * FROM `users` LIMIT 1
=> #<User @values={:email=>"neaf@19feelings.com", :username=>"neaf", :name=>"Tomasz Werbicki", :crypted_password=>"884b962862219b63308fe081f50f4c40c914de82", :salt=>"b8574dc7bc7fb392c3fa6bde577238fa2c09e487", :id=>1, :created_at=>nil}>
>> w.save
~ INSERT INTO `writeboards` (`title`) VALUES ('Title')
~ INSERT INTO `writeboard_revisions` (`content`, `user_id`, `writeboard_id`) VALUES ('Content', 1, 1)
~ SELECT * FROM `writeboard_revisions` WHERE (`id` = 1) LIMIT 1
~ INSERT INTO `writeboards` (`current_revision`, `id`, `title`) VALUES (1, 1, 'Title')
Sequel::DatabaseError: Mysql::Error Duplicate entry '1' for key 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment