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


source to share





All Articles