Explicit Primary Key with ActiveRecord
If you need to use an explicit primary key and not an AUTO_INCREMENT with ActiveRecord I wrote this snippet that has proved very handy:
module ExplicitPrimaryKey attr_accessor :pk def before_create; self.id = pk; end end
Then when you call the create method supply :pk => value along with the other values.
ActiveRecord is an ORM solution that grew out of Ruby on Rails. It is entirely separate and can be used outside of Rails.
About this entry
You’re currently reading “ Explicit Primary Key with ActiveRecord ,” an entry on bluebones.net
- Published:
- 2007.12.16
- Category:
- Programming
No comments
Jump to comment form | comments rss [?] | trackback uri [?]