DocType Types

Single DocType

A Single DocType is a DocType that has only one instance in the database. It is useful for persisting things like System Settings, which don't make sense to have multiple records.

Single DocType

Code Example

>>> todo_settings = frappe.get_doc('ToDo Settings')
>>> todo_settings.notification_frequency
'Weekly'

Schema

Single DocTypes are stored in the tabSingles table in the database, with each property having its own record.

Columns:

  • doctype

  • field

  • value

Child Table DocType

A Child DocType is doctype which can only be linked to a parent DocType. To make a Child DocType make sure to check Is Child Table while creating the doctype.

It essentially serves as a many-to-one relationship with many children to a single parent.

Example

For example, ERPNext defines a child DocType called "Purchase Receipt Item" with Is Child Table enabled:

define_child_table_doctype

Another DocType called "Purchase Receipt" has a field of type "Table", with Options set to above child doctype "Purchase Receipt Item":

define_child_table_field

Finally, the child table will be rendered in the Purchase Receipt form:

child_table_in_form

Code Example

>>> emp = frappe.get_doc('Employee', '000001')
>>> emp.as_dict()
{
    'first_name': 'Adam',
    'last_name': 'Smith',
    'qualifications': [
        {'title': 'Software Architect', 'years': '2'},
        {'title': 'DevOps Engineer', 'years': '5'},
    ]
}

Child Properties

Child documents have special properties that define their relationship to their parent :

  • parent: name of the parent.

  • parenttype: DocType of the parent.

  • parentfield: Field in the parent that links this child to it.

  • idx: Sequence (row).



Discard
Save

On this page

Review Changes ← Back to Content
Message Status Space Raised By Last update on