data icon indicating copy to clipboard operation
data copied to clipboard

manyOf relationship in nullable objects

Open diogomiguel opened this issue 1 year ago • 1 comments

With the feature introduced by https://github.com/mswjs/data/pull/257, setting a nullable object to null that has a nested relationship (tested with ManyOf), results in a TypeError: Object.defineProperty called on non-object

E.g:

const db = factory({
    a: {
        id: primaryKey(() => 1),
        nested: nullable({
            b: manyOf('b') // problematic
        })
    },
    b: {
        id: primaryKey(() => 1)
    }
});

// Works fine
db.a.create()

// Works fine
db.a.create({ nested: { b: [db.b.create()] } })

// Error
db.a.create({ nested: null })

Object.defineProperty in definePropertyAtPath is called with null (parent)

CC @yishayweb

diogomiguel avatar Oct 11 '23 14:10 diogomiguel

Hey @diogomiguel Only saw now that my PR was merged I will try to take a look at the issue you raised here

yishay-at-bay avatar Mar 22 '24 19:03 yishay-at-bay