模块:Mongoid::Clients::StorageOptions::ClassMethods

定义于:
lib/mongoid/clients/storage_options.rb

实例方法摘要折叠

实例方法详细信息

# reset_storage_options!对象

重置 store_in 选项

例子:

重置 store_in 选项

Model.reset_storage_options!


92
93
94
95
# File 'lib/mongoid/clients/storage_options.rb', line 92

def reset_storage_options!
  self.storage_options = storage_options_defaults.dup
  PersistenceContext.清除(self)
end

# storage_options_defaults哈希

获取默认存储选项。

例子:

获取默认存储选项。

Model.storage_options_defaults

返回:

  • (哈希)

    默认存储选项。



103
104
105
106
107
108
# File 'lib/mongoid/clients/storage_options.rb', line 103

def storage_options_defaults
  {
    集合: 名称.集合化.to_sym,
    客户端: :default
  }
end

# store_in (options) ⇒

为该模型提供特定的自定义默认存储选项。

例子:

默认将此模型存储在“artists”中

class Band
  include Mongoid::Document
  store_in collection: "artists"
end

默认将此模型存储在分分片的数据库中。

class Band
  include Mongoid::Document
  store_in database: "echo_shard"
end

默认情况下,将此模型存储在其他客户端中。

class Band
  include Mongoid::Document
  store_in client: "analytics"
end

将此模型与选项组合一起存储。

class Band
  include Mongoid::Document
  store_in collection: "artists", database: "music"
end

参数:

  • 选项 (哈希)

    存储选项。

选项哈希 ( options ):

  • :collection string | 符号

    collection名称。

  • :database string | 符号

    数据库名称。

  • :client string | 符号

    客户端名称。

返回:

  • ( class )

    模型类。



83
84
85
86
# File 'lib/mongoid/clients/storage_options.rb', line 83

def store_in(选项)
  验证器::存储.验证(self, 选项)
  self.storage_options = self.storage_options.合并(merge)(选项)
end