Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for composite_primary_keys #105

Merged
merged 1 commit into from
Feb 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ def mock_column(name, type, options={})
# name :string(50) not null
#

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

Expand Down