Created
January 30, 2014 20:39
-
-
Save mkwiatkowski/8718206 to your computer and use it in GitHub Desktop.
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
[2] pry(main)> Bookmark.favorited(User.first) | |
User Load (0.2ms) SELECT "users".* FROM "users" LIMIT 1 | |
Bookmark Load (0.2ms) SELECT "bookmarks".* FROM "bookmarks" INNER JOIN "favorites" ON "favorites"."bookmark_id" = "bookmarks"."id" WHERE "bookmarks"."user_id" = 1 ORDER BY created_at Desc | |
=> [] | |
[3] pry(main)> current_user = User.first | |
User Load (0.2ms) SELECT "users".* FROM "users" LIMIT 1 | |
=> #<User id: 1, email: "tyrese@faheywill.info", password_hash: "$2a$10$G47zK5tFMC9KnjZeRotQL.QsevYfpgX9C2cGbWzmY7hS...", password_salt: "$2a$10$G47zK5tFMC9KnjZeRotQL.", created_at: "2014-01-21 07:22:35", updated_at: "2014-01-21 07:22:35", name: "Jeffry Kuhic MD", role: nil> | |
[4] pry(main)> @bookmark = Bookmark.find(1) | |
Bookmark Load (21.6ms) SELECT "bookmarks".* FROM "bookmarks" WHERE "bookmarks"."id" = ? ORDER BY created_at Desc LIMIT 1 [["id", 1]] | |
=> #<Bookmark id: 1, url: "http://hoeger.biz/rachel_orn", title: "reprehenderit et", description: "Vel sunt reprehenderit amet. Id est quia amet digni...", created_at: "2013-11-27 15:12:10", updated_at: "2014-01-21 07:22:35", user_id: 1, metadata: {}> | |
[5] pry(main)> favorite = current_user.favorites.create(bookmark: @bookmark) | |
(0.1ms) begin transaction | |
SQL (2.0ms) INSERT INTO "favorites" ("bookmark_id", "created_at", "updated_at", "user_id") VALUES (?, ?, ?, ?) [["bookmark_id", 1], ["created_at", Thu, 30 Jan 2014 20:37:12 UTC +00:00], ["updated_at", Thu, 30 Jan 2014 20:37:12 UTC +00:00], ["user_id", 1]] | |
(198.0ms) commit transaction | |
=> #<Favorite id: 1, bookmark_id: 1, user_id: 1, created_at: "2014-01-30 20:37:12", updated_at: "2014-01-30 20:37:12"> | |
[6] pry(main)> favorite.valid? | |
=> true | |
[7] pry(main)> Bookmark.favorited(current_user) | |
Bookmark Load (0.3ms) SELECT "bookmarks".* FROM "bookmarks" INNER JOIN "favorites" ON "favorites"."bookmark_id" = "bookmarks"."id" WHERE "bookmarks"."user_id" = 1 ORDER BY created_at Desc | |
=> [#<Bookmark id: 1, url: "http://hoeger.biz/rachel_orn", title: "reprehenderit et", description: "Vel sunt reprehenderit amet. Id est quia amet digni...", created_at: "2013-11-27 15:12:10", updated_at: "2014-01-21 07:22:35", user_id: 1, metadata: {}>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha ha - well...hmm, must have been looking/calling/who knows :) when I tested. Great. Glad it's a non issue. Was this the correct way of implementing, or "one" way of finding favorited bookmarks for the app?