Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Support "reverse belongsTo" relations #2639

Open
SachaG opened this issue Sep 25, 2020 · 1 comment
Open

Support "reverse belongsTo" relations #2639

SachaG opened this issue Sep 25, 2020 · 1 comment
Labels

Comments

@SachaG
Copy link
Contributor

SachaG commented Sep 25, 2020

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 SachaG added the schemas label Sep 25, 2020
@Neobii
Copy link
Contributor

Neobii commented Mar 22, 2021

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`: 
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants