izatop / mongot

Modern ODM for MongoDb
ISC License
11 stars 0 forks source link

References? #2

Closed cryptiklemur closed 1 year ago

cryptiklemur commented 7 years ago

Are references possible with this lib?

izatop commented 7 years ago

@aequasi what do you mean? DBRef or program relations?

cryptiklemur commented 7 years ago

DBRef, sorry that was fairly vague. Was to excited about a non-AR ODM haha

izatop commented 7 years ago

@aequasi i may add this feature at closest time if you really need it. But, what do you think about abstraction for $lookup instead dbref and classic relations?

cryptiklemur commented 7 years ago

Havent actually read about $lookup. Looks like its supported from 3.2 and up? Is that ok with you? Looks way better than using a dbref

izatop commented 7 years ago

@aequasi yep, mongodb supports $lookup from 3.2 and this feature really faster than direct fetching data in classic way. But it may be hard a lot to code. However i'll add DBRef support for mongot.

cryptiklemur commented 7 years ago

Would definitely love to see $lookup support, but dont need it asap

izatop commented 7 years ago

@aequasi let's talk about DBRef. What do you think how it should working? Should DBRef fetched automatically or in async maner?

const doc = await OrderCollection.findOne({_id});

// fetch it automatic somewhere in internal
doc.user // available at one moment with its parent

// fetch by reference
const user = await doc.user.fetch()

// fetch by populate pattern
await doc.populate();
doc.user // available now

Or we could control it via decorators like this:

class Doc extends SchemaDocument {
    @ref({auto: true})
    user: User;
}
cryptiklemur commented 7 years ago

Could be done a couple ways. I like the decorator control. Thats handy.

Maybe also:

const doc = await OrderCollection.findOne({_id}, {populate: false});

doc.user // undefined;