I have the typical model in Core Data (for iPhone) with Departments and Employesss (Department ->> Employee).
I dont want to load all employees of a department each time I load it, so I thought I'd create the Employee as a Fetched Property. I thought I could define some Predicate like this:
employee.deparmentId = department.departmentId
but I couldn't (with Xcode graphic editor).
Now, reading some posts, Im inclined to define a relationship to-many for Department to Employee (and its reverse) and use it.
My question is: Are to-many relationship Lazy Loading? or is it going to load all my Employees in the "database" each time I create (retrieve) a list of departments?
Thanks in advance Gonso
No, objects related to to-many and to-one relationships are loaded lazily by default. However, If you need to access many of them each time you fetch a Department, then for performance reasons you may ask Core Data to load them simultaneously (this is called pre-fetching). You can do this as follow:
[fetchRequest setReturnsObjectsAsFaults:NO];
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"employees", nil]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With