Re: Fetching from related object
Re: Fetching from related object
- Subject: Re: Fetching from related object
- From: Randall Perry <email@hidden>
- Date: Sat, 24 Apr 2004 22:39:07 -0400
> On Apr 23, 2004, at 6:54 PM, Randall Perry wrote:
>
>> EOQualifier qual = EOQualifier.qualifierWithQualifierFormat(...);
>> EOFetchSpecification custFetchSpec = new EOFetchSpecification(...);
>> custInfo = ec.objectsWithFetchSpecification(custFetchSpec);
>>
>> Went to add a second fetch which grabs log entries for the past year by
>> joining on custNo:
>>
>> qual = EOQualifier.qualifierWithQualifierFormat(...);
>> logInfo = ec.objectsWithFetchSpecification(logFetchSpec);
>>
>> Then I realized that custNo is a hidden key in EOModeler for both
>> entities,
>> so this can't be done without making the keys visible.
>>
>> There is a to-one relationship defined in EOModeler between the Log and
>> CustView entities.
>>
>>
>> How would I do the logInfo fetch above without making the keys visible?
>
>
> Lots of things you should know about in this area. This is an area
> that I truly enjoy using in WebObjects/EOF so I'm going to be
> long-winded about it. This may also help some of the other newbies.
>
> You have a customer object named CustView. You have a log entry object
> named Log. BTW, your second fetch specification above was still
> fetching CustView objects, not Log objects.
Oops, you're right, though it's not quoted above:
EOFetchSpecification logFetchSpec = new EOFetchSpecification("CustView",
qual, null);
> You have a relationship
> defined in EOModeller between the two objects. I'm not going to use
> relational database terminology because it confuses the issue and
> WO/EOF makes you not care. In any case, there's a CustInfo->>Log
> relationship defined which is each CustInfo has many Log entries and
> the name of that relationship is logEntries. The reverse relationship
> from Log to CustInfo is named customer.
>
> So, you fetch a CustInfo as above. Now, how do you get the Log objects
> associated with it? The easiest best performing way is to do
> NSArray arrayOfLog = (NSArray)custInfo.valueForKey("logEntries");
>
Is it possible to use a filter with this method? I only want log records for
the past year.
> Notice that there is no fetch specification involved. EOF takes care
> of it all for you. The SELECT, the join the whole nine yards.
Pretty nifty.
--
Randall Perry
sysTame
Xserve Web Hosting/Co-location
Website Development/Promotion
Mac Consulting/Sales
http://www.systame.com/
_______________________________________________
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.