模块:Mongoid::Document
- 扩展方式:
- ActiveSupport::Concern
- 定义于:
- lib/mongoid/ 文档.rb
Overview
这是需要作为文档持久保存到数据库中的所有域对象的基本模块。
在命名空间下定义
模块: 类方法
常量摘要折叠
- ILLEGAL_KEY =
用于匹配非法 BSON 密钥的正则表达式。 请注意,bson 4.1具有应改用的常量 BSON::String::ILLEGAL_KEY。 当 Ruby 驱动程序2.3.0发布并且可以更新 Mongoid 以要求 >= 2.3.0时,可以使用 BSON 常量。
/(\A[$])|(\.)/.冻结
可组合项中包含的常量
Composable::MODULES 、 Composable::RESERVED_METHOD_NAMES
Interceptable中包含的常量
关联中包含的常量
Association::Depending中包含的常量
Association::Depending::STRATEGIES
Persistable中包含的常量
字段中包含的常量
Fields::Boolean 、 Fields::IDS 、 Fields::INVALID_BSON_CLASSES 、 Fields::StringifiedSymbol 、 Fields::TRANSLATIONS_SFX 、 Fields::TYPE_MAPPINGS
Atomic中包含的常量
实例属性摘要折叠
-
# __selected_fields ⇒ 对象
返回属性 __selected_fields 的值。
-
# new_record ⇒ 对象
只读
返回属性 new_record 的值。
Stateful中包含的属性
#destroyed 、 #flag_for_destroy 、 #previously_new_record
关联中包含的属性
属性中包含的属性
Clients::StorageOptions 中包含的属性
实例方法摘要折叠
-
# _handle_callbacks_after_instantiation (execute_callbacks) ⇒ 对象
private
如果要执行回调,则处理回调的设置和执行;否则,将适当的回调添加到待处理的回调列表中。
-
# as_document ⇒ 哈希
返回此文档及以下文档中的整个文档层次结构的哈希值。
-
#变为(klass) ⇒ 文档
返回指定类的实例,其中包含当前文档。
-
#冻结⇒ 文档
冻结文档的内部属性。
-
#frozen? ⇒ true | false
检查文档是否被冻结。
-
#哈希⇒ 整数
委托身份,以允许具有相同身份的两个记录使用类似以下内容的操作:
-
#身份⇒ 数组
文档由其类和数据库ID 绝对标识:
-
#initialize(attrs = nil, &block) ⇒ Document
实例化一个新的
Document,设置文档的属性(如果给定)。 -
# internal_state= (state) ⇒ 对象
private
设置此文档的内部状态。
-
# model_name ⇒ string
返回文档的模型名称。
-
# to_key ⇒ string
返回文档的键值。
Touchable::InstanceMethods中包含的方法
#_clear_touch_updates 、 #_gather_touch_updates 、 #_run_touch_callbacks_from_root 、 #_touchable_parent? 、 #suppress_touch_callbacks 、 #touch 、 #touch_callbacks_suppressed?
可组合项中包含的方法
Equality中包含的方法
Copyable中包含的方法
Interceptable中包含的方法
#_mongoid_run_child_after_callbacks 、 #_mongoid_run_child_before_callbacks 、 #_mongoid_run_child_callbacks 、 #_mongoid_run_child_callbacks_with_round 、 #_mongoid_run_child_callbacks_Without_round 、 #callback_executable? , #in_callback_state? 、 #pending_callbacks 、 #pending_callbacks= 、 #run_after_callbacks 、 #run_before_callbacks 、 #run_callbacks 、 #run_pending_callbacks
Validatable 中包含的方法
#begin_validate 、 #exit_validate 、 #performing_validations? 、#read_attribute_for_validation、#valid? , #validated? 、#validating、#validating_with_query?
从Traversable包含的方法
__redefine 、 #_children 、 #_descendants 、 #_parent 、 #_parent= 、 #_reset_memoized_descendants! 、#_root 、#_root? 、 #collect_children 、 #collect_descendants 、 #flag_descendants_persisted 、 #hereditary? 、 #parentize 、 #remove_child 、 #reset_persisted_descendants
Cacheable中包含的方法
Stateful中包含的方法
#destroyed? , #flag_for_destroy? , #new_record= , #new_record? , #persisted? , #previously_new_record? , #previously_persisted? , #pushable? , #readonly! , #readonly? , #settable? , #updateable?
Shardable 中包含的方法
#shard_key_field_value 、 #shard_key_fields 、 #shard_key_selector 、 #shard_key_selector_in_db
Serializable中包含的方法
Selectable中包含的方法
Reloadable中包含的方法
关联中包含的方法
#association_name 、 #embedded? , #embedded_many? , #embedded_one? , #referenced_many? , #referenced_one? , #reload_relations
Association::Reflections中包含的方法
#reflect_on_all_association 、 #reflect_on_association
Association::Macros中包含的方法
Association::Dependent中包含的方法
#apply_destroy_dependencies! , define_dependency! ,验证!
Association::Accessors中包含的方法
#__build__ 、 #create_relation 、 #reset_relation_criteria 、 #set_relation
Association::Referenced::Syncable中包含的方法
#_syncable? 、 #_synced 、 #_synced? 、 #remove_inverse_keys 、 #update_inverse_keys
Association::Referenced::CounterCache中包含的方法
define_callbacks! , #reset_counters
Association::Referenced::AutoSave中包含的方法
#__autosaving__, #autosaved?, #changed_for_autosave?, define_autosave!
Persistable中包含的方法
#atomically 、 #fail_due_to_callback! , #fail_due_to_validation!
Persistable::Unsettable 中包含的方法
Persistable::Upsertable 中包含的方法
Persistable::Updatable中包含的方法
#update, #update!, #update_attribute
Persistable::Settable中包含的方法
Persistable::Savable中包含的方法
Persistable::Renameable 中包含的方法
Persistable::Pushable 中包含的方法
Persistable::Pullable 中包含的方法
位置包含的方法
Persistable::Poppable 中包含的方法
Persistable::Multipliable中包含的方法
Persistable::Minable 中包含的方法
Persistable::Maxable中包含的方法
Persistable::Logical中包含的方法
Persistable::Incrementable中包含的方法
Persistable::Destroyable中包含的方法
Persistable::Deletable中包含的方法
Persistable::Createtable中包含的方法
Matchable中包含的方法
字段中包含的方法
#apply_default 、 #apply_defaults 、 #apply_post_processed_defaults 、 #apply_pre_processed_defaults 、 #attribute_names 、 database_field_name 、 #database_field_name 、 #dot_dollar_field? , #lazy_settable? 、 option 、 options 、 traverse_association_tree 、 #using_object_ids? , #validate_writable_field_name!
包含在Evolvable中的方法
属性中包含的方法
#allow_attributes 、#attribute_missing ? , #attribute_present? 、 #attributes_before_type_cast 、 #has_attribute? , #has_attribute_before_type_cast? 、 #process_raw_attribute 、 #read_attribute 、 #read_attribute_before_type_cast 、 #remove_attribute 、 #typed_attributes 、 #write_attribute 、 #write_attributes
Attributes::Readonly中包含的方法
Attributes::Processing中包含的方法
客户端包含的方法
clear、clients、 默认 、disconnect、reconnect、 设立 、with_name
Clients::Sessions中包含的方法
Clients::Options中包含的方法
# 集合 , #collection_name , #mongo_client , #persistence_context , #persistence_context? , #with
Clients::StorageOptions 中包含的方法
#remember_storage_options! , #storage_options
Changeable中包含的方法
#attribute_before_last_save、#changed、#changed?、#changed_attributes、#changes、#children_changed?、#children_may_have_changed!、#move_changes、#post_persist、#previous_changes、#remove_change、#saved_change_to_attribute、#saved_change_to_attribute?、#setters、#will_save_change_to_attribute?
Atomic中包含的方法
#add_atomic_pull , #add_atomic_unset , #atomic_array_add_to_sets , #atomic_array_pulls , #atomic_array_pushes , #atomic_attribute_name , #atomic_delete_modifier , #atomic_insert_modifier , #atomic_path , #atomic_paths , #atomic_position , #atomic_pulls , #atomic_pushes , #atomic_sets , #atomic_unsets , #atomic_updates , #delayed_atomic_pulls 、 #delayed_atomic_sets 、 #delayed_atomic_unsets 、 #flag_as_destroyed 、 #flag_destroys 、 #process_flag_destroys
实例属性详细信息
# __selected_fields ⇒对象
返回属性 __selected_fields 的值。
30 31 32 |
# File 'lib/mongoid/ 文档.rb', 第30行 def __selected_fields @__selected_fields end |
# new_record ⇒对象(只读)
返回属性 new_record 的值。
31 32 33 |
# File 'lib/mongoid/ 文档.rb', 第31行 def new_record @new_record end |
实例方法详细信息
# _handle_callbacks_after_instantiation (execute_callbacks) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果要执行回调,则处理回调的设置和执行;否则,将适当的回调添加到待处理的回调列表中。
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/mongoid/ 文档.rb', 第186行 def _handle_callbacks_after_instantiation(execute_callbacks) if execute_callbacks apply_defaults 产量 self if block_given? run_callbacks(:find) 除非 _find_callbacks.空? run_callbacks(:initialize) 除非 _initialize_callbacks.空? else 产量 self if block_given? self.pending_callbacks += %i[ apply_defaults find 初始化 ] end end |
# as_document ⇒哈希
返回此文档及以下文档中的整个文档层次结构的哈希值。 当所有内容而不仅仅是当前文档都需要这些属性时使用。
136 137 138 |
# File 'lib/mongoid/ 文档.rb', 第136行 def as_document BSON::文档.new(as_attributes) end |
#变为(klass) ⇒文档
返回指定类的实例,其中包含当前文档。
151 152 153 154 155 156 157 158 |
# File 'lib/mongoid/ 文档.rb', 第151行 def 变为(klass) mongoid_document_check!(klass) 成为 = klass.new(clone_document) 成为.Internal_State = Internal_State 成为 end |
#freeze ⇒ Document
冻结文档的内部属性。
51 52 53 |
# File 'lib/mongoid/ 文档.rb', 第51行 def 冻结 as_attributes.冻结 和 self end |
#frozen? ⇒ true | false
检查文档是否已冻结
61 62 63 |
# File 'lib/mongoid/ 文档.rb', 第61行 def 冻结? 属性.冻结? end |
#哈希⇒整数
委托身份,以允许具有相同身份的两个记录处理如下内容:
[ Person.find(1), Person.find(2), Person.find(3) ] &
[ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
75 76 77 |
# File 'lib/mongoid/ 文档.rb', 第75行 def 哈希 身份.哈希 end |
#身份⇒数组
文档由其类和数据库 ID 绝对标识:
Person.first.identity #=> [Person, BSON::ObjectId(' 4 f 775130 a 04745933 a 000003 ')]
87 88 89 |
# File 'lib/mongoid/ 文档.rb', 第87行 def 身份 [ self.class, _id ] end |
#initialize (attrs = nil, &block) ⇒文档
实例化一个新的Document ,设置文档的属性(如果给定)。 如果未提供任何属性,则会使用空的Hash进行初始化。
如果定义了主键,则文档的ID将设置为主键,否则将设置为新的 BSON::ObjectId string 。
104 105 106 |
# File 'lib/mongoid/ 文档.rb', 第104行 def 初始化(attrs = nil, 和块) construct_document(attrs, 和块) end |
# internal_state= (state) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
设置此文档的内部状态。 仅由 #becomes 用于帮助初始化重新键入的文档。
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mongoid/ 文档.rb', 第166行 def Internal_state=(州) self._id = 州[:id] @changed_attributes = 州[:changed_attributes] @errors = ActiveModel::Errors.new(self).点击 { |e| e.复制!(州[:errors]) } @new_record = 州[:new_record] @destroyed = 州[:destroyed] update_discriminator(州[:discriminator_key_was]) (州[:new_record]) end |
# model_name ⇒ string
返回文档的模型名称。
114 115 116 |
# File 'lib/mongoid/ 文档.rb', 第114行 def model_name self.class.model_name end |
# to_key ⇒ string
返回文档的键值。
124 125 126 |
# File 'lib/mongoid/ 文档.rb', 第124行 def to_key (持续存在? || 已销毁?) ? [ _id.to_s ] : nil end |