Skip to content

brianswko/composite_primary_keys

 
 

Repository files navigation

ActiveRecords/Rails famously doesn’t support composite primary keys. This RubyGem extends the activerecord gem to provide CPK support.

gem install composite_primary_keys
require 'composite_primary_keys'
class ProductVariation
  self.primary_keys = :product_id, :variation_seq
end
pv = ProductVariation.find(345, 12)
class 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.

See test/README_tests.rdoc

compositekeys.rubyforge.org

groups.google.com/group/compositekeys

Written by Dr Nic Williams, drnicwilliams@gmail. Contributions by many!

About

Composite Primary Keys support for Active Record

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 84.5%
  • JavaScript 14.4%
  • CSS 1.1%