Parent - Child Relationships in Model Classes

When we have two models that have ↤⇉ one - to - many relationship we may get the Children and the Parent from both sides of the relationship.


For example if we have two models with one - to many relationship like this:

Heat ↤⇉ Technique, we may then get the Parent for Technique and the Children for the Heat.


Parent for Technique

// Technique ⇇↦ Heat
extension Technique {
  var heat: Parent<Technique, Heat> {
    return parent(\.heatID)
  }
}

Children for Heat

//Heat ↤⇉ Technique
extension Heat {
  var techniques: Children<Heat, Technique> {
    return children(\.heatID)
  }
}


Prev: Model Classes in Vapor

Next: Vapor Controllers


Vapor 3 Tutorial Start


#pub #model #swift #vapor #ddl #one-to-many #many-to-one