Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created October 8, 2019 02:37
Show Gist options
  • Save joegaudet/8d6f387811cf95862bb9e0d9bde5509b to your computer and use it in GitHub Desktop.
Save joegaudet/8d6f387811cf95862bb9e0d9bde5509b to your computer and use it in GitHub Desktop.
m = Menu.includes(:menu_groups).find(1)
m.menu_groups.all
@joegaudet
Copy link
Author

Result:

  Menu Load (0.7ms)  SELECT  "menus".* FROM "menus" WHERE "menus"."deleted_at" IS NULL AND "menus"."id" = 1 LIMIT 1
  MenuGroup Load (0.7ms)  SELECT "menu_groups".* FROM "menu_groups" WHERE "menu_groups"."deleted_at" IS NULL AND "menu_groups"."menu_id" = 1 ORDER BY menu_groups.position
  MenuGroup Load (0.7ms)  SELECT "menu_groups".* FROM "menu_groups" WHERE "menu_groups"."menu_id" = 1 AND "menu_groups"."deleted_at" IS NULL ORDER BY menu_groups.position

@joegaudet
Copy link
Author

It seems to have swapped the query order, so maybe doesn't cache?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment