Created
November 9, 2011 09:11
-
-
Save chenillen/1350922 to your computer and use it in GitHub Desktop.
polymorphic counter cache problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Allen < ActiveRecord::Base | |
has_many :joins, :as => :resource | |
... | |
end | |
class Bob < ActiveRecord::Base | |
has_many :joins, :as => :resource | |
... | |
end | |
class Chris < ActiveRecord::Base | |
has_many :joins, :as => :resource | |
... | |
end | |
class Join < ActiveRecord::Base | |
belongs_to :initiator, :class_name => "User", :foreign_key => "user_id" | |
:counter_cache => .... | |
belongs_to :resource, :polymorphic => true, :counter_cache => :resources_count | |
end | |
class User < ActiveRecord::Base | |
has_many :joins | |
has_many :allens, :through => :joins, :source => :initiator | |
has_many :initial_joins, :class_name => "Join" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment