类:Mongoid::Criteria::Queryable::Selector

继承:
Smash
  • 对象
显示全部
定义于:
lib/mongoid/criteria/queryable/selector.rb

Overview

选择器是一种特殊的哈希,它知道如何序列化进入其中的值,并了解键名称的别名和区域设置。

实例属性摘要

Smash继承的属性

#aliased_associations#aliased_associations aliased_associations。#aliases#aliases 别名。#associations#associations 关联。#serializers#serializers 序列化器。

实例方法摘要折叠

Smash继承的方法

#[]#__deep_copy__#initialize

构造函数详情

该类从Mongoid::Criteria::Queryable::Smash继承构造函数

实例方法详细信息

# merge! (其他)→选择器

将另一个选择器合并到此选择器中。

例子:

合并到另一个选择器中。

selector.merge!(name: "test")

参数:

  • 其他 (哈希 |选择器)

    要合并的对象。

返回:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mongoid/criteria/queryable/selector.rb', line 20

def 合并!(其他)
  其他.each_pair do |key, |
    if .is_a?(哈希) && self[key.to_s].is_a?(哈希)
       = self[key.to_s].合并(merge)() do |_key, old_val, new_val|
        案例 _key.to_s
        when ' $in '
          new_val  old_val
        when '$nin'
          (old_val + new_val).uniq
        else
          new_val
        end
      end
    end
    if multi_selection?(key)
       = (self[key.to_s] || []).concat()
    end
    存储(key, )
  end
end

# 存储 (key, value) ⇒ Object也称为: []=

将该值存储在所提供键的选择器中。 选择器将在此步骤中处理所有必要的序列化和本地化。

例子:

在选择器中存储一个值。

selector.store(:key, "testing")

参数:

  • key ( string | Symbol )

    属性的名称。

  • ( Object )

    要添加的值。

返回:

  • ( Object )

    存储的对象。



51
52
53
54
55
56
57
58
59
60
# File 'lib/mongoid/criteria/queryable/selector.rb', line 51

def 存储(key, )
  名称, 序列化器 = storage_pair(key)
  if multi_selection?(名称)
    store_name = 名称
    store_value = evolve_multi()
  else
    store_name, store_value = store_creds(名称, 序列化器, )
  end
  (store_name, store_value)
end

# to_pipelineArray<Hash>

将选择器转换为聚合管道条目。

例子:

将选择器转换为管道。

selector.to_pipeline

返回:

  • ( Array<Hash> )

    选择器的管道条目。



69
70
71
72
73
# File 'lib/mongoid/criteria/queryable/selector.rb', line 69

def to_pipeline
  管道 = []
  管道.推动({ " $match " => self }) 除非 空?
  管道
end