noursandid / SundeedQLite

Easiest local storage library in Swift
MIT License
17 stars 2 forks source link

Retrive function - nil variable value #8

Closed FIndustries closed 4 years ago

FIndustries commented 5 years ago

First of all thank you for your amazing work. It is very easy to use.

I'm facing some strange errors when I try to use the .retrive function.

This is the console output:

2019-10-22 19:19:48.639081+0200 App[991:726609] [logging-persist] cannot open file at line 43348 of [378230ae7f]
2019-10-22 19:19:48.639134+0200 App[991:726609] [logging-persist] os_unix.c:43348: (0) open(/var/mobile/Containers/Data/Application/0E18469B-5BB9-46A6-9567-DCEC9DD4D179/Documents/SQLiteDB.sqlite) - Undefined error: 0

The app still works and the retrive function gives back the result but some variables of the objects are nil.

noursandid commented 5 years ago

Hello @FIndustries, Can you please mention what are the variables types that are being retrieved as nil? Can you please tell me if all the objects containing these variables are being retrieved as nil? Is this error occurring every time ? Or is there a specific scenario ?

Thank you

FIndustries commented 5 years ago

Hi, I think that I found the problem.

Let's use your example code:

let employee = Employee()
employee.firstName = "Nour"

let employer = Employer()
employer.id = "ABCD-1234-EFGH-5678"
employer.fullName = "Nour Sandid"
employer.employees = [employee]

employer.save()

I was trying to retrive all the Employee with Employee.retrive(... and this caused the issue.

noursandid commented 5 years ago

Oh okay, So the issue is resolved? Please add any other issue you face using this library

FIndustries commented 5 years ago

I've solved the issue but I think that the library should allow to retrive "nested" objects like Employee even if it is from Employer.

noursandid commented 5 years ago

This is doable normally, don't forget to put a primary key for the nested object with the "+" sign next to the field in the mapping function. and then you can do the below Employee.retrieve{ (employees) in print(employees) } After all, all the objects, nested or not, have to be saved in the database, so you can retrieve them.

Please try it and tell me if it works