hauntd / yii2-vote

Votes :thumbsup: :thumbsdown: // Favorite :star: // Like :heart: module for Yii 2
BSD 3-Clause "New" or "Revised" License
39 stars 11 forks source link

Vote state shows after voting but not after page reload #6

Open dbd5 opened 7 years ago

dbd5 commented 7 years ago

Hi @hauntd ,

I have found that in some cases when you click the Favourite button, the button toggles to show "Remove from favourite | 1" and the voting tables indicate that it was registered. If you immediately refresh the page it shows "Add to favourite | 0" as if the previous vote did not happen however, if you check the voting tables, the corresponding vote entry is still there.

Any suggestions on why this is happening?

Thanks

Adam

hauntd commented 7 years ago

Hi @dbd5 ,

Did you include user vote values?

$query = Item::find()
            ->withVoteAggregate('itemVote')
            ->withVoteAggregate('itemLike')
            ->withUserVote('itemVote') // <-- like this
            ->withUserVote('itemLike') // <-- like this
            ->addSelect('(itemVoteAggregate.positive - itemVoteAggregate.negative) as rating')
            ->orderBy('rating desc');
dbd5 commented 7 years ago

Hi @hauntd ,

In this particular use case, I have included the Favourite button on a page and configured the entity according to the documentation. The vote behavior has been setup as well, but I am not yet attempting to run queries.

I am just checking for consistency at the interface layer, the particular Favourite button has been configured like the others but after the button is pressed, the button toggles and the vote registers on the database but when you refresh the screen, the button does not show the vote even though the data is still in tact.

A

dbd5 commented 7 years ago

UPDATE

I can confirm that the reported issue is happening ONLY in the entities where the behaviors have been configured in the corresponding model, so commenting the behaviour out from the models resolves this issue but that will mean that the aggregate functions you provided cannot be used in queries anymore.

I think you can reproduce this by testing the widgets without setting up the behaviours in the models (toggle remembers state after screen refresh) and testing again after setting up the behaviours (toggle does not remember state after screen refresh)

Regards,

A

dbd5 commented 7 years ago

Hi @hauntd ,

You've been silent on this issue

Is it that you disagree with the issue or you are busy at this time?

dbd5 commented 5 years ago

Hi @hauntd ,

I'm happy to prepare a PR to address this if you are available to review and merge

kwazaro commented 4 years ago

When not using behaviors in models I have the same problem, described here.