tech-angels / annotator

Keep model fields commented in your rails apps.
MIT License
64 stars 5 forks source link

Problem annotating Polymorphic Association #1

Closed anithri closed 12 years ago

anithri commented 12 years ago

I got an error when it attempted to annotate a model used by other models as a polymorphic association

  A ServiceList#id [integer, primary, not null, limit=4]
  A ServiceList#service_id [integer, limit=4]
FAILURE while trying to update model ServiceList:
  uninitialized constant ServiceList::Service

For a model that looks like

class ServiceList < ActiveRecord::Base
  belongs_to :service, :polymorphic => true
  has_and_belongs_to_many :service_types
end

With a schema of:

create_table "service_lists", :force => true do |t|
  t.integer  "service_id"
  t.string   "service_type"
  t.boolean  "removed",      :default => false
  t.boolean  "accepted",     :default => false
  t.boolean  "read_only",    :default => false
  t.string   "subtype"
  t.integer  "project_id",                      :null => false
  t.datetime "created_at",                      :null => false
  t.datetime "updated_at",                      :null => false
end

Love everything else about this gem though. Thanks!

comboy commented 12 years ago

Thanks for reporting this issue :)

Indeed I missed that case when adding automatic belongs to descriptions. I think it may be cleaner to display just association name instead of related class, and this should also fix the problem with polymorphic associations. I'm at the euruko conference right now so I just pushed this quick change and I'll try to push new gem version as soon as I get back or have some time (along with a bit of code cleanup), as for now, using master should work for you.

I'm keeping this issue open because tests are missing for polymorphic association case.

anithri commented 12 years ago

Installed from master, and it fixed the missing annotations right up. Thanks for the quick response!