Created
June 20, 2017 15:50
-
-
Save AJFaraday/8a98fb183324614a35e39736c47d1e01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
> u.memberships.any? | |
# (2.9ms) SELECT COUNT(*) FROM "MEMBERSHIPS" WHERE "MEMBERSHIPS"."USER_ID" = 10080 | |
# => true | |
> u.memberships.none? | |
# Membership Load (2.4ms) SELECT "MEMBERSHIPS".* FROM "MEMBERSHIPS" WHERE "MEMBERSHIPS"."USER_ID" = 10080 ORDER BY team_id | |
# Team Load (6.0ms) SELECT "TEAMS".* FROM "TEAMS" WHERE "TEAMS"."ID" IN (1) | |
# => false | |
# The any? method is counting the number of memberships, then presumably asking in Ruby if the number is more than 1. | |
# The none? method is selecting all data about memberships, then instantiating the objects, then selecting their relation, Team. | |
# Then it presumably does a `none?` on the | |
# `any?` is checking for presence the way that the database prefers. `none?` is creating full-fat rails objects, then asking about their presence. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment