模块:Mongoid::Association::Nested::Buildable

包含在:
多个,一个
定义于:
lib/mongoid/association/nested/nested_buildable.rb

Overview

Mixin 模块,包含用于对关联执行 #accepts_nested_attributes_for 属性分配的常用功能。

实例属性摘要折叠

实例方法摘要折叠

实例属性详细信息

#关联对象

返回属性关联的值。



13
14
15
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13

def 关联
  @association
end

#属性">对象

返回属性(attribute)的值。



13
14
15
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13

def 属性
  @attributes
end

# existing对象

返回现有属性的值。



13
14
15
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13

def 现有的
  @existing
end

# options对象

返回属性选项的值。



13
14
15
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 13

def 选项
  @options
end

实例方法详细信息

# allow_destroy?true | false

确定是否允许销毁此文档。

例子:

我们允许销毁吗?

builder.allow_destroy?

返回:

  • ( true | false )

    如果设置了允许销毁选项,则为 true。



21
22
23
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 21

def allow_destroy?
  选项[:allow_destroy] || false
end

# convert_id (klass, ID ) ⇒ BSON::ObjectId | string |对象

将ID转换为其适当的类型。

例子:

转换ID 。

builder.convert_id(Person, "4d371b444835d98b8b000010")

参数:

  • klass ( class )

    我们尝试转换的类。

  • id ( string )

    ID,通常来自表单。

返回:

  • ( BSON::ObjectId | string | Object )

    转换后的 ID。



65
66
67
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 65

def convert_id(klass, id)
  klass.using_object_id? ? BSON::ObjectId.mongoize(id) : id
end

#拒绝? (文档, attrs) ⇒ true | false

如果使用宏定义选项,则返回拒绝。

例子:

是否有拒绝过程?

builder.reject?

参数:

  • 文档 (文档)

    关联的父文档

  • attrs (哈希)

    要检查拒绝情况的属性。

返回:

  • ( true | false )

    如果可拒绝,则为 True 并调用过程或方法;如果不可拒绝,则为 false。



34
35
36
37
38
39
40
41
42
43
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 34

def 拒绝?(文档, attrs)
  案例 callback = 选项[:reject_if]
    when 符号
      文档.方法(callback).元数 == 0 ? 文档.发送(callback) : 文档.发送(callback, attrs)
    when Proc
      callback.调用(attrs)
    else
      false
  end
end

# update_only?true | false

确定是否只能进行更新。 仅对一对一关联有效。

例子:

仅此更新吗?

builder.update_only?

返回:

  • ( true | false )

    如果设立了 update_only 选项,则为 true。



52
53
54
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 52

def update_only?
  选项[:update_only] || false
end