模块:Mongoid::Attributes::ClassMethods
- 定义于:
- lib/mongoid/attributes.rb
实例方法摘要折叠
-
# alias_attribute (name,original) ⇒ 对象
将提供的名称作为原始字段的别名。
-
# unalias_attribute (name) ⇒ 对象
删除字段别名。
实例方法详细信息
# alias_attribute (name,original) ⇒对象
将提供的名称作为原始字段的别名。 这将提供别名的 getter、setter、存在性检查和所有脏属性方法。
325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/mongoid/attributes.rb', line 325 def alias_attribute(名称, 原始) aliased_fields[名称.to_s] = 原始.to_s alias_method 名称, 原始 alias_method " #{ name } = ", " #{ target } = " alias_method " #{ name } ? ", " #{ target } ? " alias_method " #{ name } _change ", " #{原始} _change " alias_method " #{ name } _changed? ", " #{ original } _changed? " alias_method " reset_ #{ name } ! ", " reset_ #{ embedded } ! " alias_method " reset_ #{ name } _to_default! ", " reset_ #{ embedded } _to_default ! " alias_method " #{ name } _was ", " #{原始} _was " alias_method " #{ name } _will_change! ", " #{ target} _will_change! " alias_method " #{ name } _before_type_cast ", " #{原始} _before_type_cast " end |
# unalias_attribute (name) ⇒对象
删除字段别名。
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/mongoid/attributes.rb', line 343 def unalias_attribute(名称) 除非 aliased_fields.删除(名称.to_s) 提高 AttributeError, "字段#{ name }不是别名字段" end remove_method 名称 remove_method " #{ name } = " remove_method " #{ name } ? " remove_method " #{ name } _change " remove_method " #{ name } _changed? " remove_method " reset_ #{ name } ! " remove_method " reset_ #{ name } _to_default! " remove_method " #{ name } _was " remove_method " #{ name } _will_change! " remove_method " #{ name } _before_type_cast " end |