-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multilevel many-to-many counters #367
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Article < ActiveRecord::Base | ||
has_many :readers_articles, dependent: :destroy | ||
has_many :authors_articles, dependent: :destroy | ||
|
||
has_many :readers, through: :readers_articles, dependent: :destroy | ||
has_many :authors, through: :authors_articles, dependent: :destroy | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Author < ActiveRecord::Base | ||
has_many :authors_articles, dependent: :destroy | ||
has_many :articles, through: :authors_articles, dependent: :destroy | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AuthorsArticle < ActiveRecord::Base | ||
belongs_to :author | ||
belongs_to :article | ||
|
||
counter_culture :author, column_name: :articles_count | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Reader < ActiveRecord::Base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be reading this wrong, but it looks like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the problem with this scenario cannot be solved so easily, and the implementation is too naive. In the scenario, we have a Therefore, I don't see much benefit in this functionality. Unless leaving the technical possibility of specifying a multi-level path for the counter, and letting the implementation be up to a user, as it should be quite complex. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we close this then? |
||
has_many :readers_articles, dependent: :destroy | ||
has_many :articles, through: :readers_articles, dependent: :destroy | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ReadersArticle < ActiveRecord::Base | ||
belongs_to :reader | ||
belongs_to :article | ||
|
||
counter_culture [:article, :authors], column_name: :readers_count | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pull this out into a helper method like
Not sure if that's worth it, but it makes it clearer that the same thing is happening in both cases, just mapping in one.