Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

[SOLVED]Use the same reputation name in aggregate of aggregates always returning 0 #90

Open
ssoulless opened this issue Nov 23, 2015 · 1 comment

Comments

@ssoulless
Copy link

Hi, Im trying to create nested reputations, however I have a relationship name that is not the default, these are my models and reputation definitions:

order.rb

    class Order < ActiveRecord::Base
      belongs_to :user
      belongs_to :ofert

      has_reputation :rates, source: :user, source_of: [{reputation: :rates, of: :ofert}]
    end

ofert.rb

    class Ofert < ActiveRecord::Base
      belongs_to :user
      has_many :orders
      has_reputation :rates, source: [{reputation: :rates, of: :orders}], aggregated_by: :average, source_of: [{reputation: :karma, of: :user}]
    end

user.rb

    class User < ActiveRecord::Base
      has_many :orders
      has_many :created_oferts, class_name: 'Ofert'

     has_reputation :karma, source: [{reputation: :rates, of: :created_oferts}], aggregated_by: :average
    end

The system should work as follows:

  1. User can rate his orders
  2. The reputation of an ofert is the average of the reputation of all its orders
  3. The reputation of a user is the average of the reputation of all his oferts.

Right now is only working 1 and 2, but the reputation of an user is always 0, as you can see the relationship of users is created using an alias: has_many :created_oferts, class_name: 'Ofert'

I tried using
has_reputation :total_ofert_rates, source: [{reputation: :rates, of: :oferts}]

but it is not working.

    user.reputation_for(:total_ofert_rates)
    => 0.0
    user.reputation_for(:rates)
    => 0.0

It is always returning 0.0 for the reputations of the user. Im I doing something wrong?

@ssoulless ssoulless changed the title not working when association name is not the default Use the same reputation name in aggregate of aggregates always returning 0 Dec 8, 2015
@ssoulless ssoulless changed the title Use the same reputation name in aggregate of aggregates always returning 0 [SOLVED]Use the same reputation name in aggregate of aggregates always returning 0 Dec 8, 2015
@ssoulless
Copy link
Author

[SOLVED]
Thanks to this issue #25 I found that when you use the same reputation name it just does not work, so avoid give the same reputation name for you models.

I solved this issue just changing the name of the reputation in user.rb from rates to karma

user.rb
has_reputation :karma, source: [{reputation: :rates, of: :created_oferts}], aggregated_by: :average

ofert.rb
has_reputation :rates, source: [{reputation: :rates, of: :orders}], aggregated_by: :average, source_of: [{reputation: :karma, of: :user}]

Also make sure that you are using the exact name of your associations, for example in my case I have a has_many association with a different name than defaults:

user.rb
has_many :created_oferts, class_name: 'Ofert'
So in the reputation definition I used the same name of the association: :created_oferts instead of :oferts

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant