Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding support for composite_primary_keys

  • Loading branch information...
commit 8bfeeb2575e3161fd4b0c025c36f25dd7be26847 1 parent 4a96f3a
@garysweaver garysweaver authored
View
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 && col.name.to_sym == 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?(col.name.to_sym) : col.name.to_sym == klass.primary_key.to_sym)
col_type = (col.type || col.sql_type).to_s
if col_type == "decimal"
View
19 spec/annotate/annotate_models_spec.rb
@@ -73,6 +73,25 @@ def mock_column(name, type, options={})
EOS
end
+ 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
+#
+
+EOS
+ end
+
it "should get schema info as RDoc" do
klass = mock_class(:users, :id, [
mock_column(:id, :integer),
Please sign in to comment.
Something went wrong with that request. Please try again.