Loopback how to set up nested relationships

I have been playing with Strongloop Loopback recently ( i.e .: http://loopback.io/ ), this is a fantastic tool. I looked at their examples and it works great.

But these are basic examples; based on simple data models as shown below (which is good to start with):

example

ORIGINAL SAMPLE

Now, if you are thinking of a slightly more complex data model ... let's say a comic book data model ( http://developer.marvel.com/docs ), where you have different series consisting of several comics, and inside the comics you have a lot of characters.

UPDATE: added subseries model between series and comics

If I translate this into a loop relationship:

Serie hasMany Sub-series
Sub-series belongsTo a Serie
Sub-serie hasMany Comics
Comic belongsTo a Sub-serie
Comic hasMany Characters
Character belongsTo a Comic

, ? .

+4
2

hasMany through.

- :

Serie.hasMany(Character, {through: Comic});
+1

Source: https://habr.com/ru/post/1568027/


All Articles