<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,6 +6,9 @@ module PeteOnRails
 
       def self.included(base)
         base.extend ClassMethods
+        class &lt;&lt; base
+          attr_accessor :karmatic_objects
+        end
       end
 
       module ClassMethods
@@ -15,9 +18,13 @@ module PeteOnRails
               #{voteable_type.to_s.classify}
             end
           RUBY
-          
           include PeteOnRails::VoteFu::Karma::InstanceMethods
           extend  PeteOnRails::VoteFu::Karma::SingletonMethods
+          if self.karmatic_objects.nil?
+            self.karmatic_objects = [eval(voteable_type.to_s.classify)]
+          else
+            self.karmatic_objects.push(eval(voteable_type.to_s.classify))
+          end
         end
       end
       
@@ -35,13 +42,22 @@ module PeteOnRails
       # This module contains instance methods
       module InstanceMethods
         def karma(options = {})
-          # count the total number of votes on all of the voteable objects that are related to this object       
-          self.karma_voteable.find(:all, options_for_karma(options)).length
+          #FIXME cannot have 2 models imapcting the karma simultaneously
+          # count the total number of votes on all of the voteable objects that are related to this object
+          #2009-01-30 GuillaumeNM The following line is not SQLite3 compatible, because boolean are stored as 'f' or 't', not '1', or '0'
+          #self.karma_voteable.sum(:vote, options_for_karma(options))
+          #self.karma_voteable.find(:all, options_for_karma(options)).length
+          karma_value = 0
+          self.class.karmatic_objects.each do |object|
+            karma_value += object.find(:all, options_for_karma(object, options)).length
+          end
+          return karma_value
         end
         
-        def options_for_karma (options = {})
+        def options_for_karma (object, options = {})
+            #GuillaumeNM : 2009-01-30 Adding condition for SQLite3
             conditions = [&quot;u.id = ? AND vote = ?&quot; , self[:id] , true]
-            joins = [&quot;inner join votes v on #{karma_voteable.table_name}.id = v.voteable_id&quot;, &quot;inner join #{self.class.table_name} u on u.id = #{karma_voteable.name.tableize}.#{self.class.name.foreign_key}&quot;]            
+            joins = [&quot;inner join votes v on #{object.table_name}.id = v.voteable_id&quot;, &quot;inner join #{self.class.table_name} u on u.id = #{object.name.tableize}.#{self.class.name.foreign_key}&quot;]
             { :joins =&gt; joins.join(&quot; &quot;), :conditions =&gt; conditions }.update(options)          
         end
         </diff>
      <filename>lib/has_karma.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cd3048210b903184180756dabcdf4676725fd4c1</id>
    </parent>
  </parents>
  <author>
    <name>xlash</name>
    <email>guillaume.nourry.marquis@gmail.com</email>
  </author>
  <url>http://github.com/peteonrails/vote_fu/commit/d873f2cc72d3383b793ed5088a07aad27270bc99</url>
  <id>d873f2cc72d3383b793ed5088a07aad27270bc99</id>
  <committed-date>2009-01-30T13:30:31-08:00</committed-date>
  <authored-date>2009-01-30T13:30:31-08:00</authored-date>
  <message>Multiple objects can modify the karma of the extended class.

For example :

user.rb :::

class User &lt; ActiveRecord::Base
  has_many :posts
  has_karma :posts

  has_many :comments
  has_karma :comments</message>
  <tree>350f32db17d7d3ac462b3e07f8239133fc98fdc8</tree>
  <committer>
    <name>xlash</name>
    <email>guillaume.nourry.marquis@gmail.com</email>
  </committer>
</commit>
