In a database I have a following situation, A has many B‘s and C also has many B‘s.
What is the effective way of using Core Data relationships to search for this type of query?
- I need to search on both
a.xandc.yattributes - then I need those
B‘s which are common to both
For example:
records are separated by colon (";"), and attributes by comma (",")
A = {a;b}
C = {m;n}
B = {1,a,m;2,a,n;3,a,n;4,b,m;5,b,m;6,a,m;7,b,n;8,b,n}
Will the queries c.x = m and a.y = a result in following records from B = {1;6}?
Technical note: Core Data isn’t a relational database, so doesn’t really have ‘joins’. It’s more accurately described as an object graph.
It should be quite straightforward to implement what you want:
Set up a model with entities
A,B,C.Bhas a ‘to-many’ relationship toA(this property calleda), and a ‘to-many’ relationship toC(this property calledc).Populate this model with data as appropriate.
Then to get your ‘join’, search using a predicate as follows:
See also iPhone CoreData join.