rails-erd icon indicating copy to clipboard operation
rails-erd copied to clipboard

module_parent vs parent

Open ciembor opened this issue 5 years ago • 4 comments

Rails version: Rails 6.0.2.1

Error:

Failed: ActiveSupport::DeprecationException: DEPRECATION WARNING: 'Module#parent' has been renamed to 'module_parent'. 'parent' is deprecated and will be removed in Rails 6.1.

Solution: in lib/rails_erd/domain.rb:52 replace Rails.application.class.parent.name with Rails.application.class.module_parent.name. But...

Rails version: Rails 5.2.4.3

In this version rails-erd works, but it doesn't with changed code:

Failed: NoMethodError: undefined method 'module_parent'

I think rails-erd is very usefull also in old projects, during takeover by new developers. Solution would be to handle both cases, maybe using respond_to? or to get this name in a different way.

ciembor avatar Jul 30 '20 13:07 ciembor

We can use:

if Rails::VERSION::MAJOR >= 6
  Rails.application.class.module_parent.name
else
  Rails.application.class.parent.name
end

This is the cleanest way to handle this. We can also use partition:

Rails.application.class.name.partition('::').first

ciembor avatar Jul 30 '20 13:07 ciembor

I can confirm it's not working. Running Rails 6.1 rc1 and I'm getting this when I attempt to generate an ERD:

Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 35 models...
rails aborted!
NoMethodError: undefined method `parent' for SomeRandomApp::Application:Class
Did you mean?  present?
/app/bin/rails:4:in `require'
/app/bin/rails:4:in `<top (required)>'
/app/bin/spring:7:in `require'
/app/bin/spring:7:in `block in <top (required)>'
/app/bin/spring:4:in `tap'
/app/bin/spring:4:in `<top (required)>'
/app/config/boot.rb:4:in `load'
/app/config/boot.rb:4:in `<top (required)>'
Tasks: TOP => erd => erd:generate

gee-forr avatar Nov 09 '20 19:11 gee-forr

It looks like there's been a PR that will resolve this #345 from September 2019. It's CI builds are failing though :(

gee-forr avatar Nov 16 '20 07:11 gee-forr

This seems to be solved by #365

homonecloco avatar Feb 06 '21 00:02 homonecloco