2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 20:11:15 +00:00
books/docs/models/parent-child.md

40 lines
1.0 KiB
Markdown
Raw Normal View History

2018-02-22 07:36:28 +00:00
# Parent Child Relationship
All documents can have child documents, identified by the `Table` field.
Though child documents have their own DocType and database table, but are not to handled or viewed on their own. FrappeJS will automatically load child documents along with the parent when you use the `frappe.getDoc` method.
### Example
A sample parent-child records looks like this:
```
{
doctype: "Invoice",
customer: "Harry Potter",
items: [
{
item: "Wand",
qty: 1,
rate: 300,
amount: 300
},{
item: "Invisibility Cloak",
qty: 1,
rate: 3000,
amount: 3000
}
]
}
```
## 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)
These properties are maintained in the table automatically by FrappeJS