Vulcan icon indicating copy to clipboard operation
Vulcan copied to clipboard

Support "reverse belongsTo" relations

Open SachaG opened this issue 5 years ago • 1 comments

I'm not sure if this is the right terminology, but what I mean is:

// type 1, currently supported
post = {
  id: ..., 
  title: ...,
  commentIds: ['123foo', '456bar']
}
comment = {
  id: '123foo',
  body: ...,
}

// type 2 relation, not yet supported
post = {
  id: 'foo123', 
  title,
}
comment = {
  id,
  body,
  postId: 'foo123'
}

The way it would work is if you define a relation in your regular schema then it's assumed it's a type 1 relation since it relies on a "physical" db field (commentsIds). But if you define it in your apiSchema then it's assumed it's a type 2 relation since there would be no corresponding field to look up ids in.

SachaG avatar Sep 25 '20 00:09 SachaG

What would you call this new relationship type?

hasOne | hasMany | hasMany2

hasMany2 - this reminds me of withMulti2 which intuitively vulcan devs might thing hasMany2 is a replacement for hasMany.

hasManyForeign like foreign key?

//Post Schema
  relation: {
    fieldName: 'comments',
    typeName: '[Comment]',
    kind: 'hasMany2',
    from: `_id` // if from and to are omitted, then this is the structure that is generated
    to: `postId`: 
  }

Neobii avatar Mar 22 '21 00:03 Neobii