Detaching schema for fixtures file

Hi, I have a collection which is validated on insert with simple schema and collection2. It works fine when inserting via a form and method but I created a fixtures file and the inserts fail during the app startup with loads of errors relating to simple schema. I suspect that this si due to the auto values in the schema. Is there a way to disable the schema during the loading of the fixtures and then re-enabling after. I could not find anything like detachSchema() or removeSchema() in the simple schema or collection2 docs. I tried passing in `

Collection.insert({object},{bypasscollection2: true})` as an option in the insert but that did nothing either.

Anyone have any ideas as testing could be quite annoying if the schema keeps getting in the way.

Thanks in advance.

Use a factory to create objects, then use the factory from your fixtures. See here and here

Hi Sam, thanks for the reply but I’m aftraid I did ont understand that at all. I think I need to check out some js tutorials, since when did js have classes?

Since ES6, but you don’t need classes to have a factory. See dburles:factory

1 Like

Hi,

Have a look at Base by @themeteorchef. He uses something called faker to seed the db and I’ve found that very useful.

https://github.com/themeteorchef/base/blob/master/server/modules/generate-accounts.js

The blog post - https://themeteorchef.com/recipes/building-a-user-admin/ and https://themeteorchef.com/recipes/writing-a-database-seeder/ may also be useful.

Tat

1 Like

Thanks for sharing, Tat :slight_smile:

This looks like just the thing, and thanks for introducing me to Meteorchef, the website looks like a fantastic resource. Also, thank you Meteorchef for taking the time to provide something so useful!

I had the same problem. Fixed it using getAutoValues: false like this:

CollectionName.insert(obj, {getAutoValues: false});