到目前为止,我们只见过每个字段只能有一个值的 DocType。
然而,有时可能需要在一个记录下存储多条记录,这也被称为
多对一关系。子 DocType 是一种只能链接到父 DocType 的文档类型。
要创建子 DocType,请在创建文档类型时勾选 是否为子表。
要将子 DocType 链接到其父 DocType,请在父 DocType 中添加一行,字段类型
选择 表,选项设置为 子表。
子 DocType 记录直接附加到父文档上。
>>> person = frappe.get_doc('Person', '000001')
>>> person.as_dict()
{
'first_name': 'John',
'last_name': 'Doe',
'qualifications': [
{'title': 'Frontend Architect', 'year': '2017'},
{'title': 'DevOps Engineer', 'year': '2016'},
]
}
子属性
子文档具有一些特殊属性,用于定义它们与父文档的关系:
parent:父文档的名称。parenttype:父文档的 DocType。parentfield:父文档中链接该子文档的字段。idx:序号(行)。