I would like to hear your opinion about the effective implementation of one-to-many relationship with Python NDB. (e.g. Person(one)-to-Tasks(many))
In my understanding, there are three ways to implement it.
- Use 'parent' argument
- Use 'repeated' Structured property
- Use 'repeated' Key property
I choose a way based on the logic below usually, but does it make sense to you? If you have better logic, please teach me.
Use 'parent' argument
- Transactional operation is required between these entities
- Bidirectional reference is required between these entities
- Strongly intend 'Parent-Child' relationship
Use 'repeated' Structured property
- Don't need to use 'many' entity individually (Always, used with 'one' entity)
- 'many' entity is only referred by 'one' entity
- Number of 'repeated' is less than 100
Use 'repeated' Key property
- Need to use 'many' entity individually
- 'many' entity can be referred by other entities
- Number of 'repeated' is more than 100
No.2 increases the size of entity, but we can save the datastore operations. (We need to use projection query to reduce CPU time for the deserialization though). Therefore, I use this way as much as I can.
I really appreciate your opinion.