-
Notifications
You must be signed in to change notification settings - Fork 368
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
How to fix? ( undefined method name' for nil:NilClass ) #54
Comments
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. |
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? |
Same issue for me:
|
Same here
|
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 |
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 |
@codez: Which file did you put that code in? |
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 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 |
PR? |
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. |
Thanks for this patch |
@kerrizor @codez @rolftimmermans I am also facing the same issue as |
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 2- After this it crashed again in this method in
I rescued the line that was crashing
Hope this helps someone |
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:in
from_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:in
filtered_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:in
create'/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:in
block (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:in
block 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:in
execute'/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:in
mon_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:in
block 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:in
invoke_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:in
mon_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:in
invoke'/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:in
block (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:in
block 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:in
top_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:in
standard_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
The text was updated successfully, but these errors were encountered: