Rafael Benedettelli
Rafael Benedettelli

Reputation: 11

StrongLoop Relations

Im using strongLoop for make a simple explorer of folders and documents.

The case is very simple: one folder could contains many documents and folder.

So in strongloop y define this model hierarchy:

-Object |-----Folder |-----Document

So, in folder i defined a relation in this way: "Folder has Many Object" because a folder could contains folder, documents or either.

But i think that strongloop doesn't work with polymorphism , because only could contains child's of type "Object" strictly.

Any idea?

Upvotes: 1

Views: 621

Answers (2)

stevejpurves
stevejpurves

Reputation: 933

Is polymorphism even needed in this case?

Why not do away with Object and define Folder and Document models, then define the following relationships:

  • Folder hasMany Folder
  • Folder hasMany Document

This will result in folderId foreign keys on Document and Folder, pointing to their "parent", so there is not an issue with null keys as something always belongs to a folder.

I believe that polymorphic relations would only be useful to eliminate cases where there are multiple foreign keys between exclusive belongTo relationships, not the case here.

Upvotes: 1

superkhau
superkhau

Reputation: 2781

We do support polymorphic relations, but it's not documented very well ATM.

Here is a gist https://gist.github.com/fabien/ccce7f1de399c0227ce6 for some reference material.

You can also search https://groups.google.com/forum/#!searchin/loopbackjs/polymorphic%20relations for more information.

Upvotes: 2

Related Questions