Skip to content

Instantly share code, notes, and snippets.

@roryfranklin
Created July 14, 2017 12:27
Show Gist options
  • Save roryfranklin/c3b5bb5c309ad45240e7dc39d98cbc4e to your computer and use it in GitHub Desktop.
Save roryfranklin/c3b5bb5c309ad45240e7dc39d98cbc4e to your computer and use it in GitHub Desktop.
irb(main)> user = User.first
User Load (2.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
=> #<User id: 1, created_at: "2017-07-13 18:28:46", updated_at: "2017-07-13 18:28:46">
irb(main)> user.reviews.first.author.object_id == user.object_id
CarReview Load (1.4ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."author_id" = ? ORDER BY "reviews"."id" ASC LIMIT ? [["author_id", 1], ["LIMIT", 1]]
=> true
irb(main)> user.cars.first.user.object_id == user.object_id
Car Load (1.7ms) SELECT "cars".* FROM "cars" WHERE "cars"."user_id" = ? ORDER BY "cars"."id" ASC LIMIT ? [["user_id", 1], ["LIMIT", 1]]
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment