yii2-vote icon indicating copy to clipboard operation
yii2-vote copied to clipboard

Vote state shows after voting but not after page reload

Open dbd5 opened this issue 7 years ago • 6 comments

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

dbd5 avatar Mar 12 '17 12:03 dbd5

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');

hauntd avatar Mar 13 '17 11:03 hauntd

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 avatar Mar 13 '17 12:03 dbd5

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 avatar Mar 13 '17 12:03 dbd5

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 avatar Mar 20 '17 11:03 dbd5

Hi @hauntd ,

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

dbd5 avatar Oct 23 '18 01:10 dbd5

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

kwazaro avatar Jul 18 '19 14:07 kwazaro