Reputation: 3872
So I have a Book of poems.
Every poem has an author and there may be more then one poem on a page. My database structure looks a little bit like this
Poems(PoemName, PoemAuthor, pageNumber)
pages(PageNumber,Downloaded)
I am trying to write a method that will accept an author name and go download all of the pages that that author appears on (only if they haven't already downloaded that page).
In SQL I would simply query like this:
SELECT poems.pageNumber
FROM poems
JOIN pages ON Poems.pageNumber = pages.pageNumber
WHERE poems.PoemAuthor='foo' AND downloaded=1
GROUP BY pages.pageNumber;
Unfortunately, I am can't get it to properly join on the page numbers. Instead, core data tries to join the tables on their primary keys that they had inserted.
Basically, I need to know how I can tweak the relationship between the tables so that I can get it to join on the pageNumbers instead of coreData's primary keys.
Upvotes: 1
Views: 262
Reputation: 5346
Core Data isn't a database abstraction layer, it is an object graph management framework (and more). You shouldn't be concerned about joins and columns.
If a Poem object is related to a Page object, then you should just define that relationship in your model. I came from a SQL background, and I find Core Data easier to grok when I think about the logical entities and their relationships, and not the underlying implementation (which in any case does not have to be SQL in Core Data).
Upvotes: 1