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

Issue with scope string #26

Closed
alhajrahmoun opened this issue Jul 16, 2018 · 7 comments
Closed

Issue with scope string #26

alhajrahmoun opened this issue Jul 16, 2018 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@alhajrahmoun
Copy link

Hi there,
I'm trying to use this gem in my project and I noticed a strange behavior in the Favoritor methods.
I could favorite a favoritable item successfully but I couldn't get the favorites_count, remove_favorite or favorited? results.
after some checking, I found that the scope string is saved "favorite" in the database but when trying to select from the Favorite table you pass the string "Favorite" which means you'll get 0 results as the strings are not identical.

Thank you.

@jonhue jonhue added the bug Something isn't working label Jul 17, 2018
@jonhue jonhue self-assigned this Jul 17, 2018
@jonhue jonhue changed the title issue with scope string Issue with scope string Jul 17, 2018
@jonhue
Copy link
Owner

jonhue commented Jul 17, 2018

I looked into this and cannot see a case in which this gem would select Favorites instead of favorites. Perhaps I am just missing your point though. Please provide some information for me to reproduce and I will be happy to reopen this ticket.

@jonhue jonhue closed this as completed Jul 17, 2018
@jonhue jonhue added the question Further information is requested label Jul 17, 2018
@alhajrahmoun
Copy link
Author

alhajrahmoun commented Jul 17, 2018

Let's say we have a user and a book
when a user favorite a book the scope string is saved favorite with small 'f'
but when trying to use remove_favorite on the same book, you are looking for the record using the parameter ["scope", "Favorite"] which means you will get no records and the remove_favorite will return nil.
this is the same case with favorites_count and favorited?.

@jonhue
Copy link
Owner

jonhue commented Jul 17, 2018

Unless you are explicitly setting the scope to Favorite, this gem will neither use it to store nor to retrieve favorites.

@alhajrahmoun
Copy link
Author

No, I'm not setting the scope to Favorite

@alhajrahmoun
Copy link
Author

Okay..
I did some testing using rails console with the following cases:
1- using the gem from this repository
when running user.favorite book
I got Favorite Load (0.4ms) SELECT "favorites".* FROM "favorites" WHERE "favorites"."favoritor_id" = $1 AND "favorites"."favoritor_type" = $2 AND "favorites"."favoritable_id" = $3 AND "favorites"."favoritable_type" = $4 AND "favorites"."scope" = $5 ORDER BY "favorites"."id" ASC LIMIT $6 [["favoritor_id", 21], ["favoritor_type", "User"], ["favoritable_id", 7], ["favoritable_type", "Book"], ["scope", "favorite"], ["LIMIT", 1]]
then it will do the INSERT operation.

now, when trying to remove_favorite I got:
Favorite Load (0.8ms) SELECT "favorites".* FROM "favorites" WHERE "favorites"."favoritor_id" = $1 AND "favorites"."favoritor_type" = $2 AND "favorites"."blocked" = $3 AND "favorites"."scope" = $4 AND "favorites"."favoritable_id" = $5 AND "favorites"."favoritable_type" = $6 ORDER BY "favorites"."id" ASC LIMIT $7 [["favoritor_id", 21], ["favoritor_type", "User"], ["blocked", false], ["scope", "Favorite"], ["favoritable_id", 7], ["favoritable_type", "Book"], ["LIMIT", 1]]
and it returns nil as it didn't find the record to delete.

2- when changing default scope to be Favorite instead of favorite everything is working perfectly.

@jonhue jonhue reopened this Jul 17, 2018
@jonhue jonhue removed the question Further information is requested label Jul 17, 2018
@jonhue jonhue added the help wanted Extra attention is needed label Jul 25, 2018
@djaircarvalho
Copy link
Contributor

@mhdrahmoun this issue was already solved in master. I suggest you use gem 'acts_as_favoritor', github: 'jonhue/acts_as_favoritor' in your Gemfile until @jonhue update the gem in rubygems.org

@jonhue jonhue removed the help wanted Extra attention is needed label Jul 25, 2018
@jonhue
Copy link
Owner

jonhue commented Jul 25, 2018

Good point @djaircarvalho. Will do so. (#27)

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

3 participants