Is it possible to have a one sided one-to-many relationship between two models?
What I'm trying to achieve is a plugin architecture, where the core app server has a base set of models, but specific implementation for different clients can include custom data plugins.
So I have the notion of a core Entity
(super-simplified):
{
identity: 'entity',
attributes: {
id: 'integer',
type: 'string'
}
}
Ok, now I'm going to add a Passport
plugin to store 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 User
plugin, where a User
effectively extends Entity
, but a User
can have a number of passports. So this is what I tried first:
{
identity: 'user',
attributes: {
id: 'integer',
name: 'string',
email: 'string',
entity: {
model: 'Entity'
},
passports: {
collection: 'Passport',
via: 'entity'
}
}
}
Now things come unstuck in 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 that the Entity
is a rather abstract concept, and things like Passport
are supposed to add behaviour without having to specifically know what the concrete implementation (User
) looks like. Because I want a plugin architecture, a Passport
can't know about a User
explicitly.
It would otherwise be quite an elegant solution. Is there any way to coax Waterline into doing what I want? Thanks.