Hi,
I've run into a problem when I've been porting my code over from a SQLite database to Core Data.
The data that I'm using comes from a existing database and as such has all the relationships defined using the ID of each of the tables (or entities now that I'm using Core Data). My problem is that I want to query against a single table then use that result to propagate up though the data to get all the other data that I require.
The original database looks like:
CREATE TABLE TecAccessPoints (MAC varchar NOT NULL PRIMARY KEY UNIQUE,ZoneID integer NOT NULL,Floor integer);
CREATE TABLE Zones (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,ZoneName varchar NOT NULL,BuildingID integer,ZoneDescription varchar);
CREATE TABLE Buildings (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT,BuildingName varchar NOT NULL,CampusID integer NOT NULL,BuildingDescription varchar,Long float,Lat float);
CREATE TABLE Campuses (ID integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,CampusName varchar NOT NULL,CampusDescription text, Latitude float, Longitude float);
My original SQL query is:
SELECT DISTINCT Zones.ID, Zones.ZoneName, Buildings.ID, Buildings.BuildingName, Campuses.ID, Campuses.CampusName, Rooms.ID, Rooms.NameNumber, Rooms.Floor
FROM Zones, TecAccessPoints, Buildings, Campuses, Rooms
WHERE Campuses.ID = Buildings.CampusID
AND Buildings.ID = Zones.BuildingID
AND Zones.ID = Rooms.ZoneID
AND Zones.ID = TecAccessPoints.ZoneID
AND TecAccessPoints.MAC = '%@';
Is there any way that I can replicate this query using NSPredicate (or something similar) or is it the case that I'll have to first perform the lookup
TecAccessPoints.MAC == '%@'
Then do another lookup on the data using the returned data like:
Zones.ID == TecAccessPoints.ZoneID
And so on until I have all my results that I need?
Thanks
James