gemhome / rails-erd

retired fork, DO NOT USE. see https://github.com/voormedia/rails-erd
MIT License
0 stars 0 forks source link

How to fix? ( undefined method name' for nil:NilClass ) #15

Open bf4 opened 10 years ago

bf4 commented 10 years ago

Issue by ghost Monday May 13, 2013 at 14:39 GMT Originally opened as https://github.com/voormedia/rails-erd/issues/54


rake erd --trace * Invoke erd (first_time) * Invoke erd:generate (first_time) * Invoke erd:options (first_time) * Execute erd:options * Invoke erd:load_models (first_time) * Execute erd:load_models Loading application environment... * Invoke environment (first_time) * Execute environment Loading code in search of Active Record models... \ Execute erd:generate Generating Entity-Relationship Diagram for 35 models... Warning: Ignoring invalid model WiceGridSerializedQuery (table wice_grid_serialized_queries does not exist) Warning: Ignoring invalid model Old::OldCategory (Unknown database 'snegiri_legacy') Warning: Ignoring invalid model Old::OldField (Unknown database 'snegiri_legacy') Warning: Ignoring invalid association :resource on ActiveAdmin::Comment (polymorphic interface Resource does not exist) Warning: Ignoring invalid association :author on ActiveAdmin::Comment (polymorphic interface Author does not exist) Warning: Ignoring invalid association :admins on City (uninitialized constant City::Admin) Warning: Ignoring invalid association :assetable on Ckeditor::Asset (polymorphic interface Assetable does not exist) Warning: Ignoring invalid association :assetable on Ckeditor::Asset (polymorphic interface Assetable does not exist) Warning: Ignoring invalid association :assetable on Ckeditor::Asset (polymorphic interface Assetable does not exist) rake aborted! undefined method name' for nil:NilClass /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/domain/specialization.rb:66:in<=>' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/domain/specialization.rb:13:in sort' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/domain/specialization.rb:13:infrom_models' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/domain.rb:67:in specializations' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/diagram.rb:170:infiltered_specializations' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/diagram.rb:132:in generate' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/diagram.rb:119:increate' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/diagram.rb:74:in create' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bundler/gems/rails-erd-d29b0c29fcfa/lib/rails_erd/tasks.rake:41:inblock (2 levels) in <top (required)>' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:in call' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:inblock in execute' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:in each' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:inexecute' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:184:in block in invoke_with_call_chain' /home/zheka/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:inmon_synchronize' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:177:in invoke_with_call_chain' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:205:inblock in invoke_prerequisites' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:203:in each' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:203:ininvoke_prerequisites' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:183:in block in invoke_with_call_chain' /home/zheka/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:inmon_synchronize' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:177:in invoke_with_call_chain' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:170:ininvoke' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:143:in invoke_task' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:inblock (2 levels) in top_level' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in each' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:inblock in top_level' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:110:in run_with_threads' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:95:intop_level' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:73:in block in run' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:160:instandard_exception_handling' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:70:in run' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/bin/rake:33:in<top (required)>' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/bin/rake:23:in load' /home/zheka/.rvm/gems/ruby-2.0.0-p0@global/bin/rake:23:in

' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bin/ruby_noexec_wrapper:14:in eval' /home/zheka/.rvm/gems/ruby-2.0.0-p0@snegiri/bin/ruby_noexec_wrapper:14:in
' Tasks: TOP => erd => erd:generate

bf4 commented 10 years ago

Comment by rolftimmermans Thursday May 16, 2013 at 12:48 GMT


Thanks for your report. Could you include your database schema and ActiveRecord models? If you don't wont to post it here, you can email it to me as well.

bf4 commented 10 years ago

Comment by ldonnet Wednesday Jun 05, 2013 at 08:21 GMT


I have the same issue with my models :

undefined method `name' for nil:NilClass
/home/luc/.rbenv/versions/1.8.7-debian/gems/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:70:in `<=>'
/home/luc/.rbenv/versions/1.8.7-debian/gems/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:13:in `sort'
/home/luc/.rbenv/versions/1.8.7-debian/gems/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:13:in `from_models'

I add some log in my file and I see this :

#<RailsERD::Domain::Entity:0x007f5c0b8096e8 @model=Chouette::ActiveRecord>
#<RailsERD::Domain::Entity:0x007f5c0b8096e8 @model=Chouette::ActiveRecord>
#<RailsERD::Domain::Entity:0x007f5c0b808f68 @model=Chouette::TridentActiveRecord>
nil

for this code :

def <=>(other) # @private :nodoc:
    puts generalized.inspect
    puts other.generalized.inspect
    puts specialized.inspect
    puts other.specialized.inspect
        (generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name)
      end

And my class Chouette::TridentActiveRecord is an abstract class.

class Chouette::TridentActiveRecord < Chouette::ActiveRecord
end

module Chouette
  class ActiveRecord < ::ActiveRecord::Base
  end
end

Perhaps we need to test if generalized and specialized present?

bf4 commented 10 years ago

Comment by skydan Monday Sep 09, 2013 at 21:06 GMT


Same issue for me:

Generating Entity-Relationship Diagram for 51 models...
Warning: Ignoring invalid association :tagger on ActsAsTaggableOn::Tagging (polymorphic interface Tagger does not exist)
Warning: Ignoring invalid association :resource on ActiveAdmin::Comment (polymorphic interface Resource does not exist)
Warning: Ignoring invalid association :author on ActiveAdmin::Comment (polymorphic interface Author does not exist)
Warning: Ignoring invalid association :owner on PublicActivity::Activity (polymorphic interface Owner does not exist)
Warning: Ignoring invalid association :recipient on PublicActivity::Activity (polymorphic interface Recipient does not exist)
Warning: Ignoring invalid association :ratings on User (uninitialized constant User::Rating)
Warning: Ignoring invalid association :ratings on User (uninitialized constant User::Rating)
Warning: Ignoring invalid association :ratings on User (uninitialized constant User::Rating)
Warning: Ignoring invalid association :parents_wait_list on Program (Could not find the source association(s) :parents_wait_list or :parents_wait_list in model ProgramParentOrderRelation. Try 'has_many :parents_wait_list, :through => :program_parent_order_relations, :source => <name>'. Is it one of :activities, :program, :line_item, or :parent?)
rake aborted!
undefined method `name' for nil:NilClass
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:111:in `block (2 levels) in specializations_mapping'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:109:in `each'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:109:in `block in specializations_mapping'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:108:in `tap'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:108:in `specializations_mapping'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:81:in `specializations_by_entity_name'
/Users/skydan/.rvm/gems/ruby-1.9.3-p448@global/gems/rails-erd-1.1.0/lib/rails_erd/domain/entity.rb:92:in `children'
bf4 commented 10 years ago

Comment by amccloud Tuesday Sep 17, 2013 at 04:40 GMT


Same here

undefined method `name' for nil:NilClass
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:66:in `<=>'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:13:in `sort'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/domain/specialization.rb:13:in `from_models'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/domain.rb:67:in `specializations'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:170:in `filtered_specializations'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:132:in `generate'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:119:in `create'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/diagram.rb:74:in `create'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rails-erd-1.1.0/lib/rails_erd/tasks.rake:41:in `block (2 levels) in <top (required)>'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:197:in `block in invoke_prerequisites'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `each'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `invoke_prerequisites'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:174:in `block in invoke_with_call_chain'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/srv/www/example/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/srv/www/example/.rbenv/versions/2.0.0-p247/bin/rake:23:in `load'
/srv/www/example/.rbenv/versions/2.0.0-p247/bin/rake:23:in `<main>'
Tasks: TOP => erd => erd:generate
bf4 commented 10 years ago

Comment by rzane Monday Mar 17, 2014 at 23:29 GMT


I encountered the same issue. It does seem to be related to abstract classes, because that's what went wrong for me. I have two abstract classes in my application.

I changed the <=> method to this, so I could find out where the sort went wrong:

def <=>(other) # @private :nodoc:
  (generalized.name <=> other.generalized.name).nonzero? or (specialized.name <=> other.specialized.name)
rescue
  raise other.inspect
end

Once I found out which class it was, I added this to it, and everything worked fine:

def self.table_exists?
  true
end

It's kind of strange, especially because I only added the table_exists? to one of my two classes.

bf4 commented 10 years ago

Comment by codez Wednesday Jun 25, 2014 at 11:36 GMT


The following patch helped in my case. ERD removed the non-abstract models because it could not connect to their database, but used them again in the Specialization class. The patch makes sure that an entity really exists in the list before creating a specialization for it.

module RailsERD
  class Domain
    class Specialization
      class << self
        def abstract_from_models(domain, models)
          models.select(&:abstract_class?).
                 collect(&:descendants).
                 flatten.
                 select  { |model| domain.entity_by_name(model.name) }.
                 collect { |model|
            new(domain, domain.entity_by_name(model.superclass.name), domain.entity_by_name(model.name))
          }
        end
      end
    end
  end
end
bf4 commented 10 years ago

Comment by pcdoc80 Friday Jul 04, 2014 at 09:39 GMT


@codez: Which file did you put that code in?

bf4 commented 10 years ago

Comment by codez Saturday Jul 05, 2014 at 09:55 GMT


To fix the issue permanently, this method should be replaced in Rails ERD in lib/rails_erd/domain/specialization.rb.

To fix temporarly in my application, I require it in a rake task that is run before the erd task:

namespace :erd do
  task :options => :customize
  task :customize do
    require 'rails_erd/domain/specialization'
    require Rails.root.join('lib', 'tasks', 'erd_patch.rb')  # this is where above patch resides
  end
end