Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants