mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Query Attributes from Subentities #69
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 @ghost on GitHub (Jul 20, 2016).
I'd like to query attributes from my entity and one of it's sub-entities. I've tried few tweaks, but with no luck. This is what I have so far:
However in console I'm getting:
and in the result array I've got dictionaries with only two properties (employeeId and crystals).
Just to complete my idea - next I want to sort results like this:
Maybe I'm missing something. I'll appreciate any suggestions.
@JohnEstropia commented on GitHub (Jul 20, 2016):
A couple of things I'd like to ask,
Another thing, is "amount" a property of "CDCrystal" or of the relationship employee?
You also mentioned
@ghost commented on GitHub (Jul 20, 2016):
Thanks for quick response.
Yes "amount" is a property of "CDCrystal"
The result array contains dictionary with "employeeId" and "crystals", employee.firstName and employee.lastName are missing.
@ghost commented on GitHub (Jul 20, 2016):
Ignore,
In fact there are few crystals pointing to deactivated employees
@ghost commented on GitHub (Jul 20, 2016):
I removed crystals with deactivated employees, in order to not have nil relations, but still I'm not able to query attributes of the existing related employees.
@JohnEstropia commented on GitHub (Jul 20, 2016):
Do all subentities of CDCrystal have "employee.firstName" and "employee.lastName" keypaths? I'm not sure if CoreData allows querying a keypath if it doesn't exist on any object
@ghost commented on GitHub (Jul 20, 2016):
After my last change yes, all CDCrystals are related to employee in CDEmployee
@ghost commented on GitHub (Jul 20, 2016):
I reversed the query:
And now in result array I have dictionaries with the following attributes: "id", "firstName", "lastName".
I also leaved only one employee to test with and it got 3 related CDCrystal objects:
Still the same.
@ghost commented on GitHub (Jul 20, 2016):
In
Select.swiftininternal func applyToFetchRequest(fetchRequest: NSFetchRequest)this checkif let propertyDescription = propertiesByName[keyPath] {ignores all properties which are not part of the entity.So I don't know is it a bug or it's by design. Anyway thank you for your time.
@JohnEstropia commented on GitHub (Jul 20, 2016):
propertyDescription = propertiesByName[keyPath]This looks like the cause. Thanks for investigating!
I'll see if we can make this work with relationships' keypaths
@ghost commented on GitHub (Jul 20, 2016):
Here is my dirty temporary solution. It may help you:
Thank you!
@ghost commented on GitHub (Jul 20, 2016):
Or, please excuse this hack:
@JohnEstropia commented on GitHub (Jul 20, 2016):
@AleksandarPetrov I think you can actually just insert the compound keypath into the
propertiesToFetch:@ghost commented on GitHub (Jul 20, 2016):
Great minds think alike
@JohnEstropia commented on GitHub (Jul 21, 2016):
Hi, did the last solution work for you? If so I'll incorporate a similar fix in the next update
@ghost commented on GitHub (Jul 21, 2016):
Yes, it did the job.
@JohnEstropia commented on GitHub (Jul 21, 2016):
@AleksandarPetrov Cool, thanks :)
@julien1619 commented on GitHub (Jan 3, 2017):
I tried to query attributes of a sub-entity and it didn't found the property in this sub-entity. It seems that the NSRelationshipDescription was not used correctly, you try to access the corresponding entity using
entity, instead ofdestinationEntity.When I use
destinationEntityhere, it succeeds to find the property but crashes with this error:Uncaught exception: NSInvalidArgumentException: Attribute/relationship description names passed to setPropertiesToFetch: must match name on fetch entity. I think that both errors are linked but I cannot test it more right now.Do you have any suggestions?
@JohnEstropia commented on GitHub (Jan 3, 2017):
@julien1619 Can you post your query code?