mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Update Relationship #199
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @KrishnaKaira on GitHub (Feb 8, 2018).
Getting error:
❗ [CoreStore: Assertion Failure] DataStack+Querying.swift:105 fetchOne
↪︎ Attempted to fetch from a 'CoreStore.DataStack' outside the main thread.
I have 2 tables with one-many relation, I am using importUniqueObjects method to import data in the second table. from inside of
didInsert(from source: ImportSource, in transaction: BaseDataTransaction) throwsfunction I am not able to update the relationship.Kindly help.
What is the right way to update relationship from inside importUniqueObjects method? A code snippet would help.
Below is my code snippet:
insertion code:
CoreStore.perform( asynchronous: { (transaction) -> Void in _ = try! transaction.importUniqueObjects(Into<Content>(), sourceArray: data) }, completion: { (result) -> Void in switch result { case .success: print("DATA SAVED SUCCESSFULLY!") case .failure(let error): print(error) } }updating relationship: (inside of
didInsert(from source:, in transaction: )method)`if let siteID = self.siteId {
let filteredPred = "(siteId MATCHES '(siteID)')"
// let contentObj = transaction.edit(self)!
// contentObj.contentSite = siteManagedObject
self.contentSite = siteManagedObject
}
}
},
completion: { _ in } )`
@JohnEstropia commented on GitHub (Feb 8, 2018):
Don't dispatch asynchronously from inside
didInsert(from:in:). Use thetransactionargument directly:@KrishnaKaira commented on GitHub (Feb 8, 2018):
Hi JohnEStropia,
Thanks for the quick reply, I wish I had asked here before wasting my whole day to find a workaround. Thanks a lot for your reply it worked pretty well.
@KrishnaKaira commented on GitHub (Feb 8, 2018):
I am facing issue with fetch query as well.
I have more than 20,000 data in the database, and if I fetch data using fetchAll method it takes approximately 2.5 sec - 3 sec of time; but if I use query in a loop with fetchOne it hardly takes 0.3 sec in total.
fetchAll:
`var predicateArray = String
for item in rawData {
takes approx 3 sec (on an avg.)
fetchOne:
`for item in rawData {
takes approx 0.3 sec (on an avg.)
in rawData, there is finite number of id's depends on page size, which could be either 16 or 32.
Could you help me with this, please?
@JohnEstropia commented on GitHub (Feb 9, 2018):
Just a hunch, but
MATCHESissues a regular expression query. Try usingWhere<T>.init(_:isEqualTo:), or a variant of it, instead.@JohnEstropia commented on GitHub (Apr 14, 2018):
Closing this issue due for now. Let me know if the issues persist.