Coder Social home page Coder Social logo

Comments (14)

rolftimmermans avatar rolftimmermans commented on May 18, 2024

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.

from rails-erd.

ldonnet avatar ldonnet commented on May 18, 2024

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?

from rails-erd.

skydan avatar skydan commented on May 18, 2024

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'

from rails-erd.

amccloud avatar amccloud commented on May 18, 2024

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

from rails-erd.

rzane avatar rzane commented on May 18, 2024

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.

from rails-erd.

codez avatar codez commented on May 18, 2024

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

from rails-erd.

pcdoc80 avatar pcdoc80 commented on May 18, 2024

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

from rails-erd.

codez avatar codez commented on May 18, 2024

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

from rails-erd.

bf4 avatar bf4 commented on May 18, 2024

PR?

from rails-erd.

kerrizor avatar kerrizor commented on May 18, 2024

I just pushed a fix for this that uses a NullObject pattern to patch around the error. This should be fixed now; I'll push a new version of the gem (1.2.2) later on this evening.

from rails-erd.

ldonnet avatar ldonnet commented on May 18, 2024

Thanks for this patch

from rails-erd.

vaibhav8186 avatar vaibhav8186 commented on May 18, 2024

@kerrizor @codez This issue still exists in rails-erd (1.6.0). So can you please give your thoughts on that.

from rails-erd.

pooja-mane avatar pooja-mane commented on May 18, 2024

@kerrizor @codez @rolftimmermans I am also facing the same issue as
NoMethodError: undefined method name' for nil:NilClass`
rails-erd(1.6.0)

from rails-erd.

karamat avatar karamat commented on May 18, 2024

I have fixed this issue temporarily and successfully generate ERD diagram. 2 things I have done.

1- Tracing back to the point of crash, and found that it is happening due to relationship.destination nil . So I handled nil check by searching this in all the code

2- After this it crashed again in this method in /lib/rails-erd/domain/relationship.rb

def foreign_key_required?(association)
  if !association.active_record.abstract_class? and association.belongs_to?
    column = association.active_record.columns_hash[association.send(Domain.foreign_key_method_name)] and !column.null
  end
end

I rescued the line that was crashing

def foreign_key_required?(association)
  if !association.active_record.abstract_class? and association.belongs_to?
    begin
      column = association.active_record.columns_hash[association.send(Domain.foreign_key_method_name)] and !column.null
    rescue Exception => e
      p e.message
    end
  end
end

Hope this helps someone

from rails-erd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.