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

fixture itemName/collection name must be same? #11

Closed
ghost opened this issue Nov 21, 2013 · 4 comments
Closed

fixture itemName/collection name must be same? #11

ghost opened this issue Nov 21, 2013 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Nov 21, 2013

in basefixtureloader
var fixtureModel = mongoose.model(fixtureItem, fixtureSchema);
so looks like model name is the fixture.itemName.

in mongoosefixture
if(name === item.collection){
collectionExists = true;
}
for deletes

adding seems to use fixture.itemName and remove seems to use the fixture.collection. If I set these two the same, everything works fine. If they are different, the remove code breaks.

@mgan59
Copy link
Owner

mgan59 commented Nov 21, 2013

@roger-kaybus k will look into it. I remember thinking at one point that the interface seemed redundant, but there was a reason I made the decision and I think it has to do with the way mongoose works. I'll look into it and let you know.

@mgan59
Copy link
Owner

mgan59 commented Nov 21, 2013

Reviewed some of the code fairly quickly. I think my intention was as follows.

A little background on Mongoosejs, by default it will take whatever 'ModelKey' you pass into Mongoose.model('ModelKey', Schema) and if you do not specify a collection name in the schema.options.collection it will attempt to generate one for you. For instance if you did Mongoose.model('Kitten', Schema) it would create a collection in mongodb called kittens.

There are problems with Mongoosejs auto-generating collection names, specifically I had an instance of the model 'Facility' which was generating facilitys which is inaccurate I wanted facilities so in my schema I set the collection option to facilities. The problem then when I ran mongoose-fixture with just a collection key of 'facilities' the Mongoose.model(...) method was incapable of finding the correct model/collection mapping. Even though the delete would work since the collection name did map correctly.

So... with that said I reviewed my project that has multiple mis-matching itemName / collection names and they work fine... I think your problem might be in setting two different values you need to map your fixture.collection to the custom collection name you define on your scheme

module.exports = function(mongoose){

    var facilitySchema = mongoose.Schema({
            internalName:{type:String},
            name:{type:String},
        },
        // extra options, this overrides the default collection name
        // that would be set by model as facilitys
        {
            collection:'facilities'   
        }
    );

    return facilitySchema;
};

Let me know if this solves your problem. Maybe I'll see what my options are for warning a client that by mis-matching itemName and Collection requires the collection to be defined on the scheme. Pretty sure I can bubble the message up.

@mgan59
Copy link
Owner

mgan59 commented Nov 25, 2013

@roger-kaybus when you get a chance let me know the status and if you're all set please close the issue.

@ghost
Copy link
Author

ghost commented Nov 25, 2013

its working for me fine right now. I'll close this.

@ghost ghost closed this as completed Nov 25, 2013
This issue was closed.
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

1 participant