In my app i’m using core data as a db manager. This is more or less my database scheme:
Table: Device(
id: String,
name: String,
specsId: String
);
Table: Specs(
specsId: String,
/**/
);
The two tables are not joined in any way.
What i want to do is when i query a device from the Device table then automatically query the specs to it from the Specs table based on the matching specsId.
What is the proper way to do so?
Thanks,
Z
The proper way to do this is to drop the “specsId” field from the Device table and to create a relationship to the Specs table called something like “spec”.
This way, once you have the Device object you can just use…
to access the spec.
Without having the join you would have to create an
NSFetchRequestto get theDeviceobject that you want and then to create a newNSFetchRequestto get theSpecobject for thatDevice.The second NSFetchRequest will have a predicate something like…