lib/mongoid/association/referenced/belongs_to/buildable.rb in mongoid-7.3.5 vs lib/mongoid/association/referenced/belongs_to/buildable.rb in mongoid-7.4.0
- old
+ new
@@ -1,16 +1,13 @@
# frozen_string_literal: true
-# encoding: utf-8
module Mongoid
module Association
module Referenced
class BelongsTo
# The Builder behavior for belongs_to associations.
- #
- # @since 7.0
module Buildable
# This method either takes an _id or an object and queries for the
# inverse side using the id or sets the object.
#
@@ -33,11 +30,13 @@
def execute_query(object, type)
query_criteria(object, type).limit(1).first(id_sort: :none)
end
def query_criteria(object, type)
- model = type ? type.constantize : relation_class
- model.where(primary_key => object)
+ cls = type ? type.constantize : relation_class
+ crit = cls.criteria
+ crit = crit.apply_scope(scope)
+ crit.where(primary_key => object)
end
def query?(object)
object && !object.is_a?(Mongoid::Document)
end