#Setting hasMany Field with an empty array

1 messages · Page 1 of 1 (latest)

sturdy orchid
#

Hello,
So I have a model called order and order.items is a hasMany relationship.
Also there is another model called event that order belongs to.

So say order.items has some records filled.
And now I want to set it with an empty array, then feed it into creating an event

// order has some items initially..
order.set('items',[]);
const event = this.store.createReecord('event',{ order })
console.log(event.order.items)

And weirdly sometimes items still has original items and other times items is empty.

Does anyone know why this is?
There is no async or network involved in this...

Thanks

gentle obsidian
#

When is "sometimes"? Can you add more details?

sturdy orchid
#

@gentle obsidian it is unexpected. it is inconsistently happening.. that is a the confusing part of this issue for me..

gentle obsidian
#

It looks like an async issue. Can you await when calling event.order.items ?