Originally created by @SlinToWin on GitHub (Oct 28, 2017).
Hello i have a problem,
i get an ordered list of objects from my api and want to save it via core store.
So i flatmap the api objects in an transaction and create the CoreStoreObject models.
The Problem is, that this action don't save the models in the correct order (observable via PK)
So after fetching the core store objects via fetchAll, i get a wrong order of my items.
For Instance:
ApiModel Ids: 1,2,3,4,5,6,7
Saving to CoreStore: 3,2,4,5,1,6,7 // this should be 1,2,3,4,5,6,7
Fetching from CoreStore: 3,2,4,5,1,6,7 // this should be 1,2,3,4,5,6,7
let items = [ApiModel](....models_in_correct_order)
CoreStore.perform(asynchronous: { transaction in
return items.flatMap {
return CSTile.create(model: $0, transaction: transaction) // creates an CSTile via transaction
}.count
}, completion: { result in
})
Has anyone an idea how to work around this issue without introducing some kind of index property to my core store objects?
Originally created by @SlinToWin on GitHub (Oct 28, 2017).
Hello i have a problem,
i get an ordered list of objects from my api and want to save it via core store.
So i flatmap the api objects in an transaction and create the CoreStoreObject models.
The Problem is, that this action don't save the models in the correct order (observable via PK)
So after fetching the core store objects via fetchAll, i get a wrong order of my items.
For Instance:
```
ApiModel Ids: 1,2,3,4,5,6,7
Saving to CoreStore: 3,2,4,5,1,6,7 // this should be 1,2,3,4,5,6,7
Fetching from CoreStore: 3,2,4,5,1,6,7 // this should be 1,2,3,4,5,6,7
```
```
let items = [ApiModel](....models_in_correct_order)
CoreStore.perform(asynchronous: { transaction in
return items.flatMap {
return CSTile.create(model: $0, transaction: transaction) // creates an CSTile via transaction
}.count
}, completion: { result in
})
```
Has anyone an idea how to work around this issue without introducing some kind of `index` property to my core store objects?
adam
added the question label 2025-12-29 18:24:07 +01:00
One way to do this is to create an object with an ordered relationship, but even then you cannot observe on those objects like you could a ListMonitor. If you need to observe that order you will need a sorting index.
@JohnEstropia commented on GitHub (Oct 29, 2017):
You will need to store the order somewhere.
One way to do this is to create an object with an ordered relationship, but even then you cannot observe on those objects like you could a `ListMonitor`. If you need to observe that order you will need a sorting index.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @SlinToWin on GitHub (Oct 28, 2017).
Hello i have a problem,
i get an ordered list of objects from my api and want to save it via core store.
So i flatmap the api objects in an transaction and create the CoreStoreObject models.
The Problem is, that this action don't save the models in the correct order (observable via PK)
So after fetching the core store objects via fetchAll, i get a wrong order of my items.
For Instance:
Has anyone an idea how to work around this issue without introducing some kind of
indexproperty to my core store objects?@JohnEstropia commented on GitHub (Oct 29, 2017):
You will need to store the order somewhere.
One way to do this is to create an object with an ordered relationship, but even then you cannot observe on those objects like you could a
ListMonitor. If you need to observe that order you will need a sorting index.@SlinToWin commented on GitHub (Oct 30, 2017):
Ok, just inserted a sorting index :)