Closed creativetim closed 11 years ago
With your reputation definition, right behavior is:
voter1 = Voter.create
voter2 = Voter.create
poll = voter1.polls.create
poll.powervote(voter2)
voter1.powervotes
=> 1
voter2.powervotes
=> 0
However, I think you are trying to make:
voter2.powervotes
=> 1
Reputation chain can be done only through model association.
One work around you can do is:
Poll.evaluated_by(:powervotes, voter2)
=> [<Poll ...>]
Poll.evaluated_by(:powervotes, voter2).count
=> 1
That works.
So a :voter_powervotes reputation on the Voter model is unnecessary in this case since all I need to do is count how many powervotes have been cast on behalf of a user.
Glad it works. Please close this issue :)
This is also a SO post: http://stackoverflow.com/questions/18246904/twitter-activerecord-reputation-counting-primary-reputations-as-non-primary-rep
I have two models: Voters and Polls.
A Voter can vote on a Poll in two ways: 1) up/down vote 2) power vote
I have up/down voting working, but I want to be able to know how many power votes a user has accumulated in aggregate as they can only have a certain amount.
poll.rb
voter.rb
When I powervote() on a poll as a voter and then call Voter.powervotes it returns 0. I think this is because of STI.
Assuming Voter ID 1 and Poll ID 1, when I record a powervote as a user on a poll, using this setup, 3 reputations are created in my rs_reputations table.
powervotes voter_powervotes score
Everything seems fine, until you dig a little deeper: voter_powervotes' target_id seems to be pulling the wrong ID. In this case it's pulling 4 - it should be 1. I think it's doing this because Poll ID 1 has a column called voter_id and its value is 4. I don't care about who the Poll belongs to I just care about each user's powervote count.
Is there a better way to setup the associations between models or have I found a bug?