3lvis / DATAStack

100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer
Other
214 stars 44 forks source link

Optional relationship not returning data #103

Closed pgawlowski closed 7 years ago

pgawlowski commented 7 years ago

Let's assume core data entity structure like this:

Cart:
-> CartEntry - To-Many, Optional

CartEntry:
-> product -> To-One, Optional

There is CartEntry with product in my Cart - coreData seems to be ok. I'm fetching Cart and as a result I've got:

Cart:
-> entries: [
      {
              product: nil
      }
] 

However when I changed

Cart:
-> CartEntry - To-Many

Everything seems to be fine - fetch result got also products.

3lvis commented 7 years ago

Hi,

I don't follow, could you post a pic of your Core Data model?

pgawlowski commented 7 years ago

screen shot 2017-03-20 at 13 07 01

3lvis commented 7 years ago

Thanks! So, the problem here is that after inserting a few cart entries to a cart, doing:

let result = cart.hyp_dictionary(using: .snakeCase, andRelationshipType: .array)

Doesn't print any of the cart entries, right?

pgawlowski commented 7 years ago

Nope. Cart entries are ok. In Core Data Editor I can see proper cartEntries as well as product in every cartEntry - I'm sure that relation exists.

However let result = cart.hyp_dictionary(using: .snakeCase, andRelationshipType: .array) doesn't print any products in cart entry unless I uncheck optional for product reference in CartEntry entity.

Right now I'm trying to reset whole DB and check it once again.

3lvis commented 7 years ago

I see, that's very strange.

pgawlowski commented 7 years ago

After reset it's working perfect. I will leave this issue open and try to reproduce this problem in another 24h :) Else I'll just close this issue.

3lvis commented 7 years ago

Awesome. Gonna put my timer for 24 hours :P