Git Product home page Git Product logo

Comments (17)

vadimdemedes avatar vadimdemedes commented on July 20, 2024

There's no ability to save sub-models, but you can save document with nested fields. Is that what you want?

from mongorito.

amit777 avatar amit777 commented on July 20, 2024

Well let's say I have a domain model. And within domain model I have an array of server documents which I want to have a model for. Very much like mongoose child schema models.

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

No, this feature is not supported currently.

from mongorito.

amit777 avatar amit777 commented on July 20, 2024

I actually just realized the mongoose does not allowed for subjdocument child schema models. They do allow subdocument arrays of models though:
eg:

Not Allowed:

parentSchema = new Schema({
attr: 'hi',
child:  childSchema  // not allowed
children: [childSchema] //allowed
})

from mongorito.

jaredpetersen avatar jaredpetersen commented on July 20, 2024

👍 -- I was thinking of switching over from Mongoose to Mongorito but I can't without this feature.

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

Is this possible yet?

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

No, not yet. If this functionality is critical for you, I recommend going with Mongoose, because I'm very short on time lately, so I can't promise any ETA.

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

@vdemedes I guess I can do a pull request with some of the code I have come up with.

I have one question you might be able to help with, how would you go about figuring out where the sub document class is. With Doc.get('sub').get('test') you can load the entity into the parent class because it is already imported; But do you have any idea how you might figure out what class to load the sub into?

Cheers

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

Actually i guess it could be done with module.parent however not the best solution... It would require modules never change their directory

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

Something like:

https://github.com/Alex-iFactory/eden/blob/master/bin/bundles/core/model.js

May work, not sure how to make the getAttributes more efficient?

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

Not sure I understand your question, could you clarify?

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

If we were to allow sub-documents; wouldn't when we run a query on a parent document we need to require the sub-document class:

class parentDocument extends mongorito.Model {

}

class childDocument extends mongorito.Model {

}

let ParentDocument = new parentDocument({
    'child' : yield new childDocument({
        'title' : 'test'
    }).save();
});

In the above case, finding the parent document would return information about the child document, but I am unsure how to use this information to require and load the childDocument class. What would you use to store the location of the childDocument class in the parentDocument document?

Cheers

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

Oh I see now. We could modify Query#populate() to convert inline data to models straight away. Right now populate() works just like in Mongoose. Given this document:

{
  "comments": [1, 2, 3]
}

where [1, 2, 3] are ObjectIDs, we can find documents with those ids and create a Comment model for each of them:

let post = await Post.populate('comments', Comment).findOne();
// post.comments now is an array of Comment models

So we could modify implementation of .populate() to avoid find operation and create a new model straight away, if current array item is not an ObjectID:

if (isObjectId(item)) {
  return model.findById(item);
} else {
  return new model(item);
}

Let me know if that's unclear ;)

from mongorito.

EdenCoder avatar EdenCoder commented on July 20, 2024

That works, I will put together a pull request this week.

Cheers

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

Cool!

from mongorito.

sascha1337 avatar sascha1337 commented on July 20, 2024

is this merged yet?

from mongorito.

vadimdemedes avatar vadimdemedes commented on July 20, 2024

Nope, it was never implemented. Hope to implement this in the next major version - #138.

from mongorito.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.