4

I'm playing with Strongloop Loopback lately (ie: http://loopback.io/), it's a fantastic tool. I went through their sample cases and it works just great.

But this is basic examples ; based on simple data models as below (which is fine to start):

example

ORIGINAL SAMPLE

Now, if you think about a slightly more complicated data model... let say a data model about comics (http://developer.marvel.com/docs), where you have various series which are made up of several comics, and within comics you have many characters.

UPDATE: added a sub-series model between series and comics

If I translate this in loopback relations:

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

Here is my issue, how to get all characters for a given serie? How should I describe this relation.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109

2 Answers2

1

You are looking for hasMany through.

What about something like this:

Serie.hasMany(Character, {through: Comic});
oldergod
  • 15,033
  • 7
  • 62
  • 88
  • Yes, I agreed with that, my sample case was not relevant... :) What's about nested relations with more levels (updated my sample case)? – Matthieu Bilbille Dec 18 '14 at 09:20
0

See this example for relation examples: https://github.com/strongloop/loopback-example-relations-basic

superkhau
  • 2,781
  • 18
  • 9
  • I have seen this example, but I don't answer my problem. I'm talking about nested relations (more than 1 level). Loopback doesn't seem to support multiple hasMany:through relations. Similar problem here with Ruby: http://stackoverflow.com/questions/2383479/ruby-on-rails-multiple-has-many-through-possible – Matthieu Bilbille Dec 19 '14 at 11:02