How to fetch / include values from a type that is a Parent

#1

If I have two types with a primary/foreign key relationship, how can I fetch from the “child” type, and also include some fields from the parent?

For example, I have two types:

ItemPurchaseOrderHistory (parent type) and OrderDelayRiskScoreHistory (child type)

The two types each have the field purchaseOrderId that links these two types.

The following works to fetch from the parent and include child rows:

c3Grid(ItemPurchaseOrderHistory.fetch({include: 'this, orderDelayRiskScoreHistory.score', limit: 1}))

What I want to do instead, however, is to fetch from the child, and include some parent fields:

c3Grid(OrderDelayRiskScoreHistory.fetch({include: 'this, <parent_field>', limit: 10}))

Thanks

Paul

0 Likes

#2

To include parent fields the child type must have a reference field to the parent. Something like:

entity type OrderDelayRiskScoreHistory {
...
parent: ItemPurchaseOrderHistory
...
}

The include can then contain “fieldA, fieldB, parent.parentFieldA, parent.parentFieldB”.

0 Likes