¶ ↑
Composite Primary Keys for ActiveRecords¶ ↑
SummaryActiveRecords/Rails famously doesn't support composite primary keys. This RubyGem extends the activerecord gem to provide CPK support.
¶ ↑
Installationgem install composite_primary_keys
¶ ↑
Usagerequire 'composite_primary_keys' class ProductVariation < ActiveRecord::Base self.primary_keys = :product_id, :variation_seq end pv = ProductVariation.find(345, 12)
¶ ↑
Factoriesclass ModelWithCompositeKeys < ActiveRecord::Base set_primary_keys :id, :updated_at end FactoryGirl.define do factory :model_with_composite_keys do sequence( :id ) { |n| [n,Time.now] } name "Brett" end end
It even supports composite foreign keys for associations.
See compositekeys.rubyforge.org for more.
¶ ↑
Running TestsSee test/README_tests.rdoc
¶ ↑
Url¶ ↑
Questions, Discussion and Contributionsgroups.google.com/group/compositekeys
¶ ↑
AuthorWritten by Dr Nic Williams, drnicwilliams@gmail. Contributions by many!