GithubHelp home page GithubHelp logo

Comments (7)

mgan59 avatar mgan59 commented on July 22, 2024

So I understand the result.

The expectation would be the o would get sent to the fixture-loader and all the o.families would need to be inserted into mongo and their _ids returned and embedded into the references defined within the o.people. So essentially clients are defining these tree structures in a data-fixture file and mongoose-fixture is then deciphering the collections and handling all the embedded documents in a more literate form?

from mongoose-fixture.

hal-gh avatar hal-gh commented on July 22, 2024

I am not sure that mongo would need to be touched while the o object is being created. Surely references are simply two properties that have the same value, regardless of whether they are in the same or different collections? The _id properties' ObjectId values can be created before o is processed by mongoose-fixtures.

The snippet above is a working example of what would be passed to mongoose-fixture. The only difficulty would be how the section of BaseFixtureLoader.js that I patched the other day would differentiate between an object of documents and an object of collections.

A possible solution could be to check the existence of a specific property, as follows.

        if(_.isPlainObject(globalFixtureData)){
            if(globalFixtureData.fixtureCollection){
                // handle each property as a collection whose properties contain documents
            }
            if(globalFixtureData.dataFixtures){
                fixtureSet = globalFixtureData.dataFixtures;
            } else {
                globalFixtureData = _.values(globalFixtureData);
            }
         }
         if(_.isArray(globalFixtureData)){
             fixtureSet = globalFixtureData;
         }

However, there may be a much more elegant way of doing it.

from mongoose-fixture.

mgan59 avatar mgan59 commented on July 22, 2024

your right wouldn't need to touch mongo. just thinking of a case where you generate these _ids and then during the insertion phase something goes wrong and then you have these _ids with no match. Where inserting into mongo would give you some assurance that the fk-doc-ids exist. Maybe that isn't a concern and ideally that shouldn't/wouldn't happen. so yeah the implementation provided looks easy enough.

how would the --reset or --remove methods work? edit the way the mongoose-config works to accept multiple collections names to drop from?

from mongoose-fixture.

hal-gh avatar hal-gh commented on July 22, 2024

This scenario isn't really intended for fixtures that reference data that already exists in the db. For that, I think your approach (that I linked to above) would be better.

Here, any references must exist in the object. If they don't, javascript will inherently throw an error. I don't think there needs to be any special logic or error checking to handle this.

from mongoose-fixture.

hal-gh avatar hal-gh commented on July 22, 2024

Devising a way to integrate this into the fixtures user interface may be trickier. Could you just build the whole o object and then only process the collections specified by the `fixtureConfig.fixtureListings config?

from mongoose-fixture.

mgan59 avatar mgan59 commented on July 22, 2024

Think that would be the tricky part.

I'm not opposed to supporting this interface, I could see it being useful for some to simplify their fixtures. I of course have my own use cases at the moment and need to get some changes for schema/model loading for a 0.3.0 release which will break apis for people. Why I'm incrementing off the 0.2.x line.

Anyways, if you want to put in the effort to implement this interface and write the test then I'm willing to merge it. If you build it from the 0.2.3 tag I'll help port it to the 0.3.0 version. I hope to have 0.3.0 out in the next day or so.

from mongoose-fixture.

hal-gh avatar hal-gh commented on July 22, 2024

When I said "trickier", I just meant, to make the decision. As long as the behaviour is documented, I don't think it would cause a problem.

I've realised that other projects use a similar type of interface
https://github.com/tdegrunt/mongodb-fixtures/blob/master/fixtures/wines.json

Pow fixtures also uses something similar but, when I tried it, it didn't work as documented.

from mongoose-fixture.

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.