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

Additional checks #82

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 col.name.to_sym == klass.primary_key.to_sym
attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I solve this problem this way:

attrs << "primary key" if col.name.to_sym == klass.primary_key.try(:to_sym)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"try" seems like a fun method. Where is it defined?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if we can use ActiveSupport methods since some people use
Annotate without Rails.

https://github.com/rails/rails/blob/6ef9fda1a39f45e2d18aba4881f60a19589a2c77/activesupport/lib/active_support/core_ext/object/try.rb#L32

On Fri, Jul 13, 2012 at 4:33 PM, arturtr
[email protected]
wrote:

@@ -82,7 +82,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 col.name.to_sym == klass.primary_key.to_sym
    
  •    attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
    

http://api.rubyonrails.org/classes/Object.html#method-i-try


Reply to this email directly or view it on GitHub:
https://github.com/ctran/annotate_models/pull/82/files#r1163133

Alex Chaffee - [email protected]
http://alexchaffee.com
http://twitter.com/alexch


col_type = (col.type || col.sql_type).to_s
if col_type == "decimal"
Expand Down Expand Up @@ -318,7 +318,7 @@ def get_model_class(file)
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def get_loaded_model(model_path)
ObjectSpace.each_object.
select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
select { |c| Class === c && c.ancestors.respond_to?(:include?) && c.ancestors.include?(ActiveRecord::Base) }.
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end

Expand Down