Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deepmerge.all breaks ObjectId  #16

@lawsontaylor

Description

@lawsontaylor

I'm using Factoria to generate fixtured for some integration tests.
I'm using MongoDb and sometimes I need knowledge of what an Object's '_id' will be before it's created.
Passing overrides to a Model like in the examples below returns an Object that cannot be written directly to MongoDb because Deepmerge.all clones 'every property from all types of objects'.

`
Factory.define("User", (faker) => ({
_id: new ObjectId(),
firstname: faker.name.firstName(),
lastname: faker.name.lastName(),
email: faker.internet.email(),
timezone: faker.address.timeZone(),
}))

const user_id = new ObjectId();
const user = Factory("User", 1, { _id: user_id });
`

Can we modify the deepmerge.all on line 52 of index.ts to accept options that implements isMergeableObject and only clones properties from non-instantiated objects?

{ isMergeableObject: isPlainObject }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions