Created
July 14, 2022 16:11
-
-
Save exegeteio/ec4dd378610fa06a356de0df564b32e0 to your computer and use it in GitHub Desktop.
Eager loading after Active Record create?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.create(email: 'whatever@nowhere', team_id: 123) | |
# ??? eager loading ??? | |
# user.eager_load(team: {memberships: :admins}) # Maybe? | |
# user.reload(includes: {team: {memberships: :admins}}) # Adds an extra fetch. | |
# N+1 on `memberships` and `admins`. | |
notify_emails = user.team.memberships.admins.collect(:email) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment