One-to-many waterline with arbitrary foreign keys

Is it possible to have a one-to-many one-way relationship between two models?

What I am trying to achieve is a plugin architecture where the main application server has a basic set of models, but the specific implementation for different clients may include custom data plugins.

So I have the concept of a core Entity

(super-simplified):

{ identity: 'entity', attributes: { id: 'integer', type: 'string' } }

Ok, now I'm going to add a plugin Passport

for storing login credentials.

{ identity: 'passport', attributes: { id: 'integer', protocol: 'string', username: 'string', password: 'string', entity: { model: 'Entity' } } }

So far so good. Now I want to add a plugin User

where User

it expands effectively Entity

but User

can have multiple passports. So this is what I tried in the first place:

{ identity: 'user', attributes: { id: 'integer', name: 'string', email: 'string', entity: { model: 'Entity' }, passports: { collection: 'Passport', via: 'entity' } } }

Now things are falling into Waterline (but it's a perfectly reasonable data model). Here's the error:

Trying to associate a collection attribute to a model that doesn't have a Foreign Key. user is trying to reference a foreign key in passport

The point of the exercise is, which Entity

is a fairly abstract concept, and things like Passport

should add behavior without knowing specifically what a concrete implementation ( User

) looks like . Since I want a plugin architecture Passport

can't explicitly know about User

.

Otherwise it would be a pretty elegant solution. Is there a way to persuade Waterline to do what I want? Thank.

+3
waterline


source to share


No one has answered this question yet

Check out similar questions:

3
What is the translation of 'collection' type waterling with mongodb adapter?
2
Waterline - mixing AND & OR
2
MongoDb Waterline object (filled) lost its type AND prototype functions
2
Sails 10.x waterline: Which attribute type to use for Mongo objectID
1
Sails allow multiple entries with identical primary keys of a string like
1
Sails.js db request by foreign key
0
Unable to add or update child row: foreign key constraint will fail CONSTRAINT 'PageChild_Page_Id_fk' FOREIGN KEY ('PageId') REFERENCES page ('Id')
0
Waterline Queries Similar to HQL
0
Sails.js - Waterline Model - Association for yourself
0
Sailsjs Model.find () not getting foreign key



All Articles
Loading...
X
Show
Funny
Dev
Pics