Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

How to generate ids for reference #9

Open
facultymatt opened this issue Sep 11, 2015 · 5 comments
Open

How to generate ids for reference #9

facultymatt opened this issue Sep 11, 2015 · 5 comments
Assignees

Comments

@facultymatt
Copy link

Lets say you want to know the id of an object you've seeded to reference on another object.

module.exports.seed = {
  person: [
    {
      firstName: 'Luke',
      lastName:  'Skywalker',
      nemesis: vador.id
    },
    {
      firstName: 'Darth',
      lastName:  'Vader',
      nemesis: skywalker.id
    }
  ]
}

One way to do this is to generate the Ids outside of the config, for example:

var ObjectID = require('mongodb').ObjectID;
var vadorId = new ObjectID();
var skywalkerId = new ObjectID();

module.exports.seed = {
  person: [
    {
      id: skywalkerId,
      firstName: 'Luke',
      lastName:  'Skywalker',
      nemesis: vadorId
    },
    {
      id: vadorId,
      firstName: 'Darth',
      lastName:  'Vader',
      nemesis: skywalkerId
    }
  ]
}

But the above solution is not ideal because the Id generation in this case is tied to mongo, and if we switched to SQL for example we'd need to refactor this (not very Waterline).

Thoughts?

@frostme
Copy link
Owner

frostme commented Sep 11, 2015

Love your example by the way (nemesis). I hadn't even though of referencing ids. That makes total sense, any type of relational db would have them, and even nosql dbs at least of the referencing ability. I will definitely check this out over the weekend and let you know what I come up with, but this is definitely a good add on.

@arca223
Copy link

arca223 commented Oct 28, 2016

Any news on this feature ? Seems pretty important and awesome ! ;)

@frostme frostme self-assigned this Jan 3, 2017
@frostme
Copy link
Owner

frostme commented Jan 3, 2017

@facultymatt @arca223 this is now I believe a completely necessary feature and I'll be working on this this week and should have the new version out next week with this possiblity

@gerardo-navarro
Copy link

@frostme
How far did you get with this feature?

@nagarjun
Copy link

nagarjun commented Jan 8, 2018

@frostme Has there been any update on this? It was the first thing that came to my mind when I found your amazing package. Thanks.

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

No branches or pull requests

5 participants