Loopback - Crear relación "hasMany through"



Este tipo de relación es en las que se usa un modelo intermediario para almacenar las relaciones entre dos tablas.
Esta es una relación de ejemplo entre "tipos de calificación" y "puestos":

 $ slc loopback:relation                                  ⬡ 0.12.7 [±score ●●]
? Select the model to create the relationship from: scoreType
? Relation type: has many
? Choose a model to create a relationship with: jobTitles
? Enter the property name for the relation: jobTitles
? Optionally enter a custom foreign key:
? Require a through model? Yes
? Choose a through model: scoreTypeJobTitle


slc loopback:relation                                  ⬡ 0.12.7 [±score ●●]
? Select the model to create the relationship from: scoreTypeJobTitle
? Relation type: belongs to
? Choose a model to create a relationship with: scoreType
? Enter the property name for the relation: scoreType
? Optionally enter a custom foreign key:

 slc loopback:relation                                  ⬡ 0.12.7 [±score ●●]
? Select the model to create the relationship from: scoreTypeJobTitle
? Relation type: belongs to
? Choose a model to create a relationship with: jobTitles
? Enter the property name for the relation: jobTitles
? Optionally enter a custom foreign key:




hasManyThrough
-Sí nos importa el modelo intermediario
-Contiene ids y propiedades
-Muchos a muchos-

hasAndBelongsToMany
-No nos importa el modelo intermediario
-Solo contiene ids
-Muchos a muchos-

hasMany

0 Comentarios

Publicar un comentario