views:

425

answers:

3

I have a CoreData model with 4 entities.

Model screenshot -> http://img96.imageshack.us/img96/7857/screenshot20100209at182.png

State

-StateName

Location:

-locationName (attribute)

-locationDescription

-locationActivities (relatinship)

-state (relationship)

LocationActivities:

-location (relationship)

-activity (relationship)

Activities

-activityName(attribute)

-locationsActivities (relationship)

How can i write a query that selects all Locations that have

(activity = 'Golf' OR activity = 'Swimming') AND state = 'LA'

+1  A: 
Tim
what about the LocationActivities linking table?
Jonathan Ramirez
Fixed, but why is that entity there in the first place? You can (I believe) simply have a one-to-many relationship from Location to Activity.
Tim
this does not work. i get the error: 'to-many key not allowed here'.I have added another entity as suggested by http://stackoverflow.com/questions/1903177/coredata-many-to-many-relationships-and-nspredicate
Jonathan Ramirez
What predicate did you use that gave you that error? With a direct to-many relationship from Location to Activity (even if the inverse is also to-many), I think that you should be able to do "ANY activities.activityName == %@" as part of your predicate.
gerry3
A: 

As an aside, you need to stop thinking in terms of tables and queries for Core Data. In Core Data those specifics of only the sqllite persistent store and you never see them or deal with them.

Entities are not tables and relationships are not linking tables. Trying to cram the object model into an SQL in your head will lead you to grief because Core Data does not work like SQL.

TechZen
A: 

I just noticed that in your screen shot, your LocationActivities entity is actually spelled LocationAtivities (note the missing "c").

That is enough to wreck your graph. Any predicate that looks for LocationActivities will fail.

Errors like this make me hate programming. I seem to spend more time tracking down typos than I do fixing design errors.

TechZen