Skip to content

Commit

Permalink
Additional backport
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Jan 17, 2024
1 parent c6f51a4 commit 11a5fd4
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 31 deletions.
6 changes: 3 additions & 3 deletions lib/mongoid/association/bindable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def bind_foreign_key(keyed, id)
# @param [ Mongoid::Document ] typed The document that stores the type field.
# @param [ String ] name The name of the model.
def bind_polymorphic_type(typed, name)
return unless _association.type
return unless _association.type && !typed.frozen?

try_method(typed, _association.type_setter, name)
end
Expand All @@ -151,7 +151,7 @@ def bind_polymorphic_type(typed, name)
# @param [ Mongoid::Document ] typed The document that stores the type field.
# @param [ String ] name The name of the model.
def bind_polymorphic_inverse_type(typed, name)
return unless _association.inverse_type
return unless _association.inverse_type && !typed.frozen?

try_method(typed, _association.inverse_type_setter, name)
end
Expand All @@ -167,7 +167,7 @@ def bind_polymorphic_inverse_type(typed, name)
# @param [ Mongoid::Document ] doc The base document.
# @param [ Mongoid::Document ] inverse The inverse document.
def bind_inverse(doc, inverse)
return unless doc.respond_to?(_association.inverse_setter)
return unless doc.respond_to?(_association.inverse_setter) && !doc.frozen?

try_method(doc, _association.inverse_setter, inverse)
end
Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/embedded/embedded_in/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Mongoid
module Association
module Embedded
class EmbeddedIn

# Transparent proxy for embedded_in associations.
# An instance of this class is returned when calling the
# association getter method on the child document. This
# class inherits from Mongoid::Association::Proxy and forwards
# most of its methods to the target of the association, i.e.
# the parent document.
class Proxy < Association::One

# Instantiate a new embedded_in association.
#
# @example Create the new association.
Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/embedded/embeds_many/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Mongoid
module Association
module Embedded
class EmbedsMany

# Transparent proxy for embeds_many associations.
# An instance of this class is returned when calling the
# association getter method on the parent document. This
Expand All @@ -18,7 +17,6 @@ class Proxy < Association::Many

# Class-level methods for the Proxy class.
module ClassMethods

# Returns the eager loader for this association.
#
# @param [ Array<Mongoid::Association> ] associations The
Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/embedded/embeds_one/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Mongoid
module Association
module Embedded
class EmbedsOne

# Transparent proxy for embeds_one associations.
# An instance of this class is returned when calling the
# association getter method on the parent document. This
# class inherits from Mongoid::Association::Proxy and forwards
# most of its methods to the target of the association, i.e.
# the child document.
class Proxy < Association::One

# The valid options when defining this association.
#
# @return [ Array<Symbol> ] The allowed options when defining this association.
Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Mongoid
module Association

# This module contains the core macros for defining associations between
# documents. They can be either embedded or referenced.
module Macros
Expand Down Expand Up @@ -58,7 +57,6 @@ def associations

# Class methods for associations.
module ClassMethods

# Adds the association back to the parent document. This macro is
# necessary to set the references from the child back to the parent
# document. If a child does not define this association calling
Expand Down
4 changes: 3 additions & 1 deletion lib/mongoid/association/nested/many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def update_nested_relation(parent, id, attrs)
first = existing.first
converted = first ? convert_id(first.class, id) : id

if existing.exists?(_id: converted)
# The next line cannot be written as `existing.exists?(_id: converted)`,
# otherwise tests will fail.
if existing.where(_id: converted).exists? # rubocop:disable Rails/WhereExists
# document exists in association
doc = existing.find(converted)
if destroyable?(attrs)
Expand Down
10 changes: 4 additions & 6 deletions lib/mongoid/association/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

module Mongoid
module Association

# This class is the superclass for all association proxy objects, and contains
# common behavior for all of them.
class Proxy
extend Forwardable

alias_method :extend_proxy, :extend

# Specific methods to prevent from being undefined.
#
# @api private
KEEP_METHODS = %i[
KEEPER_METHODS = %i[
send
object_id
equal?
Expand All @@ -25,11 +26,9 @@ class Proxy
extend_proxies
].freeze

alias_method :extend_proxy, :extend

# We undefine most methods to get them sent through to the target.
instance_methods.each do |method|
next if method.to_s.start_with?('__') || KEEP_METHODS.include?(method)
next if method.to_s.start_with?('__') || KEEPER_METHODS.include?(method)

undef_method(method)
end
Expand Down Expand Up @@ -201,7 +200,6 @@ def execute_callbacks_around(name, doc)
end

class << self

# Apply ordering to the criteria if it was defined on the association.
#
# @example Apply the ordering.
Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/referenced/belongs_to/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Mongoid
module Association
module Referenced
class BelongsTo

# Transparent proxy for belong_to associations.
# An instance of this class is returned when calling the
# association getter method on the subject document.
Expand Down Expand Up @@ -99,7 +98,6 @@ def persistable?
end

class << self

# Get the Eager object for this type of association.
#
# @example Get the eager loader object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Mongoid
module Association
module Referenced
class HasAndBelongsToMany

# Transparent proxy for has_and_belongs_to_many associations.
# An instance of this class is returned when calling
# the association getter method on the subject document.
Expand All @@ -13,10 +12,8 @@ class HasAndBelongsToMany
# i.e. the array of documents on the opposite-side collection
# which must be loaded.
class Proxy < Referenced::HasMany::Proxy

# Class-level methods for HasAndBelongsToMany::Proxy
module ClassMethods

# Get the eager loader object for this type of association.
#
# @example Get the eager loader object
Expand Down Expand Up @@ -90,7 +87,6 @@ def <<(*args)
end
unsynced(_base, foreign_key) and self
end

alias_method :push, :<<

# Appends an array of documents to the association. Performs a batch
Expand Down
1 change: 0 additions & 1 deletion lib/mongoid/association/referenced/has_many/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Mongoid
module Association
module Referenced
class HasMany

# Transparent proxy for has_many associations.
# An instance of this class is returned when calling the
# association getter method on the subject document. This class
Expand Down
1 change: 0 additions & 1 deletion lib/mongoid/association/referenced/has_one/eager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Mongoid
module Association
module Referenced
class HasOne

# Eager class for has_one associations.
class Eager < Association::Eager

Expand Down
2 changes: 0 additions & 2 deletions lib/mongoid/association/referenced/has_one/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Mongoid
module Association
module Referenced
class HasOne

# Transparent proxy for has_one associations.
# An instance of this class is returned when calling the
# association getter method on the subject document. This class
# inherits from Mongoid::Association::Proxy and forwards most of
# its methods to the target of the association, i.e. the
# document on the opposite-side collection which must be loaded.
class Proxy < Association::One

# Class-level methods for HasOne::Proxy
module ClassMethods

Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/deprecation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def initialize
#
# @return [ Array<Proc> ] The deprecation behavior.
def behavior
@behavior ||= Array(lambda do |message, callstack, _deprecation_horizon, _gem_name|
@behavior ||= Array(lambda do |*args|
logger = Mongoid.logger
logger.warn(message)
logger.debug(callstack.join("\n ")) if debug
logger.warn(args[0])
logger.debug(args[1].join("\n ")) if debug
end)
end
end
Expand Down

0 comments on commit 11a5fd4

Please sign in to comment.