Skip to content
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

Fix Mongoid dependent strategy #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/impressionist/models/mongoid/impression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Impression
include Mongoid::Timestamps

include Impressionist::CounterCache
Impressionist::SetupAssociation.new(self).set

field :impressionable_id, type: BSON::ObjectId
field :impressionable_type
Expand All @@ -23,4 +22,5 @@ class Impression

after_save :impressionable_counter_cache_updatable?

belongs_to :impressionable, polymorphic: true
end
17 changes: 13 additions & 4 deletions lib/impressionist/models/mongoid/impressionist/impressionable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Impressionist
module Impressionable

# extends AS::Concern
include Impressionist::IsImpressionable
extend ActiveSupport::Concern

# Overides impressionist_count in order to provide mongoid compability
def impressionist_count(options={})
Expand All @@ -19,8 +17,19 @@ def impressionist_count(options={})
# Count all distinct impressions unless the :all filter is provided
distinct = options[:filter] != :all
distinct ? imps.where(options[:filter].ne => nil).distinct(options[:filter]).count : imps.count
end
end

module ClassMethods
def is_impressionable(options={})
has_many :impressions,
as: :impressionable,
dependent: :delete

@impressionist_cache_options = options

true
end
end
end
end

Expand Down