类:Mongoid::Criteria::Queryable::Options

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

Overview

选项是传递给 MongoDB 查询的选项的哈希表示,例如跳过、限制和排序条件。

实例属性摘要

Smash继承的属性

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

实例方法摘要折叠

Smash继承的方法

#[] , #initialize

构造函数详情

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

实例方法详细信息

# __deep_copy__选项

执行选项的深度复制。

例子:

执行深度复制。

options.__deep_copy__

返回:

  • 选项

    复制的选项。



87
88
89
90
91
92
93
# File 'lib/mongoid/criteria/queryable/options.rb', line 87

def __deep_copy__
  self.class.new(别名, 序列化器, 关联, aliased_associations) do |copy|
    each_pair do |key, |
      copy.合并!(key => .__deep_copy__)
    end
  end
end

#个字段哈希

获取字段选项的便捷方法。

例子:

获取字段选项。

options.fields

返回:

  • (哈希)

    字段选项。



18
19
20
# File 'lib/mongoid/criteria/queryable/options.rb', line 18

def 字段
  self[:fields]
end

# limit整数

获取限制选项的便捷方法。

例子:

获取限制选项。

options.limit

返回:

  • ( Integer )

    限制选项。



28
29
30
# File 'lib/mongoid/criteria/queryable/options.rb', line 28

def limit
  self[:limit]
end

# skip整数

获取跳过选项的便捷方法。

例子:

获取跳过选项。

options.skip

返回:

  • ( Integer )

    跳过选项。



38
39
40
# File 'lib/mongoid/criteria/queryable/options.rb', line 38

def 跳过
  self[:skip]
end

#sortHash

获取排序选项的便捷方法。

例子:

获取排序选项。

options.sort

返回:

  • (哈希)

    排序选项。



48
49
50
# File 'lib/mongoid/criteria/queryable/options.rb', line 48

def sort
  self[:sort]
end

# store (key, value, localize = true) ⇒ Object也称为: []=

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

例子:

在选项中存储一个值。

options.store(:key, "testing")

参数:

  • key ( string | Symbol )

    属性的名称。

  • ( Object )

    要添加的值。

返回:

  • ( Object )

    存储的对象。



62
63
64
# File 'lib/mongoid/criteria/queryable/options.rb', line 62

def 存储(key, , localize = true)
  (key, 发展(, localize))
end

# to_pipelineArray<Hash>

将选项转换为聚合管道友好选项。

例子:

将选项转换为管道。

options.to_pipeline

返回:

  • ( Array<Hash> )

    管道形式的选项。



73
74
75
76
77
78
79
# File 'lib/mongoid/criteria/queryable/options.rb', line 73

def to_pipeline
  管道 = []
  管道.推动({ " $skip " => 跳过 }) if 跳过
  管道.推动({ " $limit " => limit }) if limit
  管道.推动({ " $sort " => sort }) if sort
  管道
end