Skip to content
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

Eager load models when running erd #1200

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

gazayas
Copy link
Contributor

@gazayas gazayas commented Nov 25, 2023

#1058

Reading up on voormedia/rails-erd#322, Zeitwork::Loader.eager_load_all will ensure all of our application's models will be included when running bundle exec erd.

There were suggestions to put that line inside config/environment.rb, but I ultimately went with this fix which isolates it specifically to the scope of the erd command.

I'm not 100% happy having to include a file like this, but it seems like there still isn't a fix for Rails 7.

With that being said, the command is generating a PDF for the same amount of models (31) before and after this fix. I've decided to submit this PR though so we don't miss anymore models if some are added in the future and aren't captured if we aren't eager loading.

Just for reference, here's the output that I'm getting.

> bundle exec erd
Loading application in 'bullet_train'...
Generating entity-relationship diagram for 31 models...
Warning: Ignoring invalid model Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator (table scaffolding_absolutely_abstract_creative_concepts_collaborators does not exist)
Warning: Ignoring invalid association :event_type on Webhooks::Outgoing::Event (model Webhooks::Outgoing::EventType exists, but is not included in domain)
Warning: Ignoring invalid association :collaborators on Scaffolding::AbsolutelyAbstract::CreativeConcept (model Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator exists, but is not included in domain)
Warning: Ignoring invalid association :country on Address (model Addresses::Country exists, but is not included in domain)
Warning: Ignoring invalid association :region on Address (model Addresses::Region exists, but is not included in domain)
Warning: Ignoring invalid association :scaffolding_absolutely_abstract_creative_concepts_collaborators on Membership (model Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator exists, but is not included in domain)
Warning: Ignoring invalid association :scaffolding_absolutely_abstract_creative_concepts_collaborators on User (model Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator exists, but is not included in domain)
Diagram saved to 'erd.pdf'.

The tests are failing here, but after merging main on a different branch you can see that they're passing.

Screenshot from 2023-11-25 14-52-03

@jagthedrummer jagthedrummer merged commit a68935f into jeremy/rails-erd Dec 4, 2023
0 of 8 checks passed
@jagthedrummer jagthedrummer deleted the rails-erd-eager-load branch December 4, 2023 17:09
@jagthedrummer
Copy link
Contributor

Thanks, @gazayas! 🤘

jagthedrummer added a commit that referenced this pull request Dec 4, 2023
* Add `rails-erd`

Fixes #723

* Add extension to rails-erd to ensure we're getting all of the models (#1200)

---------

Co-authored-by: Gabriel Zayas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants