Re: Fetching the next child object [NEWBIE]
Re: Fetching the next child object [NEWBIE]
- Subject: Re: Fetching the next child object [NEWBIE]
- From: Art Isbell <email@hidden>
- Date: Thu, 26 Jun 2003 20:38:41 -1000
On Thursday, June 26, 2003, at 07:52 PM, Goodbye Bill wrote:
1. I have three objects in my database that have a parent-child
relationship. For now, let's say they are:
Musician
Album
Song
2. I have fetched a specific "Musician" object using an
EOFetchSpecification
and have that object loaded in memory;
3. I would like to simply get a single Album by specifying the "Title."
WHERE I AM:
The only way I can figure to do this is pull the ID of the Musician
object
and then use an AndQualifier with the "Title" AND the "ID" of the
parent
musician.
Primary keys shouldn't generally be used in EOF. That's the
conventional way of thinking about relational database access.
Instead, follow the object graph. Musician has a to-many relationship
to Album (e.g., "Musician.albums"). When you send your musician object
(e.g., "musician") an albums() message, an array will be returned.
This will be a fault array if these albums have not been previously
fetched, but you needn't concern yourself about this; EOF will do the
right thing by fetching the objects represented by the fault array, if
necessary. Instead, you can take advantage of in-memory filtering
using EOQualifier API:
EOQualifier qualifier = EOQualifier.qualifierWithQualifierFormat("title
like %@", new NSArray(title));
// Assume that only one album with the title "title" exists.
Album album =
EOQualifier.filterArrayWithQualifier(musician.albums(), qualifier).lastO
bject();
Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.