Create an object in a child table with frappe object

823 views
Skip to first unread message

Brendan Kiu

unread,
Aug 19, 2014, 12:31:13 AM8/19/14
to erpnext-dev...@googlegroups.com
Hello, I'm working with the frappe object, and am wondering how to handle parent/child objects. I have a parent DocType and a child DocType. If I had code like this

```
p_doc = frappe.new_doc("Parent DocType")
c_doc = frappe.new_doc("Child DocType")

# Set various fields...

# Is there something simple like
p_doc.set_child(c_doc)
```
I noticed you do a 
```
value.parent = self.name
value.parenttype = self.doctype
value.parentfield = key
```
in base_document.py. Is that the only way to reliably do this? Thanks.

Rushabh Mehta

unread,
Aug 19, 2014, 4:38:02 AM8/19/14
to erpnext-dev...@googlegroups.com
```
doc = frappe.new_doc("Parent")
doc.append("childfield", { ... })
```


--
Note:
 
If you are posting an issue,
 
1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/c97dabf3-10ac-46ba-aceb-44f6413c0642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rushabh Mehta

unread,
Aug 19, 2014, 4:38:11 AM8/19/14
to erpnext-dev...@googlegroups.com
```
doc = frappe.new_doc("Parent")
doc.append("childfield", { ... })
```


On 19-Aug-2014, at 10:01 am, Brendan Kiu <bren...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages