Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composite primary keys in ruby on rails

I am trying to use http://compositekeys.rubyforge.org/ in order to have composite primary keys in my activerecord models.

I already added gem 'composite_primary_keys', '=3.1.0' to my Gemfile. Now I am trying to setup my first modelclass as follows.

class StringProperty < ActiveRecord::Base
    self.primary_keys :entity_id, :property_id
    set_table_name "problem.string_property"
    attr_accessible :entity_id, :property_id, :value
end

But all I get is: enter image description here

What am I doing wrong? :(

like image 730
Coxer Avatar asked Dec 13 '12 08:12

Coxer


1 Answers

The following will work I think.

require 'composite_primary_keys'
class StringProperty < ActiveRecord::Base
    self.primary_keys = :entity_id, :property_id
    set_table_name "problem.string_property"
    attr_accessible :entity_id, :property_id, :value
end
like image 84
VenkatK Avatar answered Oct 07 '22 08:10

VenkatK