Skip to content

Commit 789a308

Browse files
committed
Updating the embeds compatibility layer
1 parent cf305ed commit 789a308

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/carrierwave/mongoid.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ def store_previous_changes_for_#{column}
109109
110110
def find_previous_model_for_#{column}
111111
if self.embedded?
112-
if self.respond_to?(:__metadata) # Mongoid >= 4.0.0.beta1
113-
ancestors = [[ self.__metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.__metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
114-
else # Mongoid < 4.0.0.beta1
115-
ancestors = [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
116-
end
112+
ancestors =
113+
if self.respond_to?(:_association) # Mongoid >= 7.0.0.beta
114+
[[ self._association.key, self._parent ]].tap { |x| x.unshift([ x.first.last._association.key, x.first.last._parent ]) while x.first.last.embedded? }
115+
elsif self.respond_to?(:__metadata) # Mongoid >= 4.0.0.beta1 < 7.0.0.beta
116+
[[ self.__metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.__metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
117+
else # Mongoid < 4.0.0.beta1
118+
[[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
119+
end
117120
first_parent = ancestors.first.last
118121
reloaded_parent = first_parent.class.unscoped.find(first_parent.to_key.first)
119122
association = ancestors.inject(reloaded_parent) { |parent,(key,ancestor)| (parent.is_a?(Array) ? parent.find(ancestor.to_key.first) : parent).send(key) }

0 commit comments

Comments
 (0)