Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


add support for composite_primary_keys #105

merged 1 commit into from

6 participants

Gary S. Weaver Alex Chaffee Ian Leitch Turadg Aleahmad Matt Garrison I-feng Yang
Gary S. Weaver

Fix for: #89

Wrote test, but wasn't able to get dependency issue with wrong gem worked out. Tested manually and works as spec expects.

Alex Chaffee

Sorry about that -- I wrote Wrong and it's had some dependency problems for a few months now... Something to do with Ryan updating his various ruby parsing gems.

Thanks for the patch! I'll look at it soon.

Ian Leitch

+1 would like this merged.

Turadg Aleahmad turadg merged commit 8bd159c into from
Turadg Aleahmad

Until Travis is working again, I'll take @garysweaver at his word that this works. ;)

Gary S. Weaver


Matt Garrison

Since Travis isn't working for you, I'm just chiming in with feedback that this works for my 'composite_primary_keys' models that annotate previous would not handle.

Thanks to all of you for your work on this gem.

Turadg Aleahmad

thanks @mattgarison for the confirmation. and of course thanks @garysweaver for making it work. :smile:

I-feng Yang

Been waiting for this for a while, any gem release planned?

Turadg Aleahmad turadg referenced this pull request from a commit
Turadg Aleahmad turadg fix spec for composite_primary_keys #105 99cc11e
Turadg Aleahmad

@captainmike I just pushed 2.6.0.beta2 to rubygems

I-feng Yang

great! will check it out.

Gary S. Weaver


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 9, 2012
  1. Gary S. Weaver
This page is out of date. Refresh to see the latest.
2  lib/annotate/annotate_models.rb
@@ -113,7 +113,7 @@ def get_schema_info(klass, header, options = {})
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null
- attrs << "primary key" if klass.primary_key && == klass.primary_key.to_sym
+ attrs << "primary key" if klass.primary_key && (klass.primary_key.is_a?(Array) ? klass.primary_key.collect{|c|c.to_sym}.include?( : == klass.primary_key.to_sym)
col_type = (col.type || col.sql_type).to_s
if col_type == "decimal"
19 spec/annotate/annotate_models_spec.rb
@@ -73,6 +73,25 @@ def mock_column(name, type, options={})
+ it "should get schema info even if the primary key is array, if using composite_primary_keys" do
+ klass = mock_class(:users, nil, [
+ [mock_column(:a_id, :integer), mock_column(:b_id, :integer)],
+ mock_column(:name, :string, :limit => 50)
+ ])
+ AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
+# Schema Info
+# Table name: users
+# a_id :integer not null
+# b_id :integer not null
+# name :string(50) not null
+ end
it "should get schema info as RDoc" do
klass = mock_class(:users, :id, [
mock_column(:id, :integer),
Something went wrong with that request. Please try again.