Originally created by @martheli on GitHub (May 24, 2017).
I have read over the readme but I have not seen any examples of how to pull data from two entities if there is a relationship. For example if I had one entity that was Manager and one that was Employee. I wanted the result output to show the employee and the employee's manager. Is this type of query supported in CoreStore?
Originally created by @martheli on GitHub (May 24, 2017).
I have read over the readme but I have not seen any examples of how to pull data from two entities if there is a relationship. For example if I had one entity that was Manager and one that was Employee. I wanted the result output to show the employee and the employee's manager. Is this type of query supported in CoreStore?
adam
added the question label 2025-12-29 18:23:28 +01:00
let employee = CoreStore.fetchOne(
From<Employee>(),
Where( ... ) // some condition
)
and then access the manager
letmanager=employee.manager
Does this answer your question?
@JohnEstropia commented on GitHub (May 24, 2017):
I'm not sure I understood your question. You can fetch the employee and then access the manager for that employee. So if you have these entities:
```swift
class Employee: NSManagedObject {
// ...
@NSManaged var manager: Manager?
}
class Manager: NSManagedObject {
// ...
@NSManaged var employee: Employee?
}
```
You can fetch the employee
```
let employee = CoreStore.fetchOne(
From<Employee>(),
Where( ... ) // some condition
)
```
and then access the manager
```swift
let manager = employee.manager
```
Does this answer your question?
Ok yes that does answer it. Do you need to set up the entities as classes like you show above for it to work or can I use the xcmappingmodel file to set up the entities only?
@martheli commented on GitHub (May 24, 2017):
Ok yes that does answer it. Do you need to set up the entities as classes like you show above for it to work or can I use the xcmappingmodel file to set up the entities only?
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 @martheli on GitHub (May 24, 2017).
I have read over the readme but I have not seen any examples of how to pull data from two entities if there is a relationship. For example if I had one entity that was Manager and one that was Employee. I wanted the result output to show the employee and the employee's manager. Is this type of query supported in CoreStore?
@JohnEstropia commented on GitHub (May 24, 2017):
I'm not sure I understood your question. You can fetch the employee and then access the manager for that employee. So if you have these entities:
You can fetch the employee
and then access the manager
Does this answer your question?
@martheli commented on GitHub (May 24, 2017):
Ok yes that does answer it. Do you need to set up the entities as classes like you show above for it to work or can I use the xcmappingmodel file to set up the entities only?
@JohnEstropia commented on GitHub (May 24, 2017):
You can create the xcdatamodeld file and let Xcode automatically generate the class code for you.