Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No favoritors/favorited? returns False after inserting Favorite. #5

Closed
NicWickman opened this issue Jun 10, 2018 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@NicWickman
Copy link

This is simply not working for me. Console seems to say that favorites are created, but there's nothing then when I try to retrieve it.

`Created database 'db/test.sqlite3'
-- create_table("favorites", {:force=>:cascade})
-> 0.0625s
-- create_table("resources", {:force=>:cascade})
-> 0.0318s
-- create_table("users", {:force=>:cascade})
-> 0.0307s
-- create_table("favorites", {:force=>:cascade})
-> 0.0693s
-- create_table("resources", {:force=>:cascade})
-> 0.0274s
-- create_table("users", {:force=>:cascade})
-> 0.0322s
ec2-user:~/environment/knowhow (adding-save) $ rails console
Running via Spring preloader in process 6072
Loading development environment (Rails 5.2.0)

resource = Resource.first
Resource Load (0.2ms) SELECT "resources".* FROM "resources" ORDER BY "resources"."id" ASC LIMIT ? [["LIMIT", 1]]
=> #<Resource id: 1, title: "WaniKani", url: "https://www.wanikani.com/", content: "Learn over 2000 Japanese Kanji over the course of ...", created_at: "2018-06-10 20:05:29", updated_at: "2018-06-10 20:05:29">
user = User.first
User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
=> #<User id: 1, email: "test@example.com", created_at: "2018-06-10 20:05:52", updated_at: "2018-06-10 20:05:52">
user.favorite resource
Favorite Load (0.2ms) SELECT "favorites".* FROM "favorites" WHERE "favorites"."favoritor_id" = ? AND "favorites"."favoritor_type" = ? AND "favorites"."favoritable_id" = ? AND "favorites"."favoritable_type" = ? AND "favorites"."scope" = ? ORDER BY "favorites"."id" ASC LIMIT ? [["favoritor_id", 1], ["favoritor_type", "User"], ["favoritable_id", 1], ["favoritable_type", "Resource"], ["scope", "favorite"], ["LIMIT", 1]]
(0.1ms) begin transaction
Resource Load (0.1ms) SELECT "resources".* FROM "resources" WHERE "resources"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
Favorite Create (2.2ms) INSERT INTO "favorites" ("favoritable_type", "favoritable_id", "favoritor_type", "favoritor_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["favoritable_type", "Resource"], ["favoritable_id", 1], ["favoritor_type", "User"], ["favoritor_id", 1], ["created_at", "2018-06-10 20:06:21.177285"], ["updated_at", "2018-06-10 20:06:21.177285"]]
(7.9ms) commit transaction
=> #<Favorite id: 1, favoritable_type: "Resource", favoritable_id: 1, favoritor_type: "User", favoritor_id: 1, scope: "favorite", blocked: false, created_at: "2018-06-10 20:06:21", updated_at: "2018-06-10 20:06:21">

user.favorited? resource
(0.3ms) SELECT COUNT() FROM "favorites" WHERE "favorites"."blocked" = ? AND "favorites"."scope" = ? AND "favorites"."favoritor_id" = ? AND "favorites"."favoritor_type" = ? AND "favorites"."favoritable_id" = ? AND "favorites"."favoritable_type" = ? [["blocked", 0], ["scope", "Favorite"], ["favoritor_id", 1], ["favoritor_type", "User"], ["favoritable_id", 1], ["favoritable_type", "Resource"]]
=> false
resource.favoritors_count
(0.2ms) SELECT COUNT(
) FROM "favorites" WHERE "favorites"."favoritable_id" = ? AND "favorites"."favoritable_type" = ? AND "favorites"."blocked" = ? AND "favorites"."scope" = ? [["favoritable_id", 1], ["favoritable_type", "Resource"], ["blocked", 0], ["scope", "Favorite"]]
=> 0

@jonhue
Copy link
Owner

jonhue commented Jun 14, 2018

Fixed with #7

@jonhue jonhue closed this as completed Jun 14, 2018
@jonhue jonhue added the bug Something isn't working label Jul 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants