Comments (14)
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.
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.
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.
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.
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.
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.
@codez: Which file did you put that code in?
from rails-erd.
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.
PR?
from rails-erd.
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.
Thanks for this patch
from rails-erd.
@kerrizor @codez This issue still exists in rails-erd (1.6.0). So can you please give your thoughts on that.
from rails-erd.
@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.
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)
- Error when trying to run on Ubuntu HOT 3
- Polluting global scope with rake task helper method
- rails-red conflicts with discard gem HOT 1
- Add instructions for how to use rails-erd in a gem
- Bug with --only and -only_recursion_depth
- Rails 7 deprecation warnings HOT 1
- FrozenError: can't modify frozen String: "boolean" HOT 4
- Clarify how to customise output directory
- Warnings on Rails internal tables that have not been created HOT 2
- Spec failure on Graphviz fonts when running locally
- Disabling auto-generate on db:migrate HOT 2
- Changing output file path. HOT 3
- Use translations for models and attributes
- rails db:migrate
- compond foreign key to_sym on Array during rake db:migrate HOT 1
- Assertion failed: (filename && *filename), function try_dlopen, file ltdl.c, line 1204. HOT 1
- Can I customize the data instead of auto-generating it from my ActiveRecord relations?
- Enhancment: Mermaid style uses classDiagram, not erDiagram
- NoMethodError: undefined method `name' for nil:NilClass (seems to be related to PaperTrail)
- Support Eclipse Layout Kernel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-erd.