• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fetching from related object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetching from related object


  • Subject: Re: Fetching from related object
  • From: Arturo PĂ©rez <email@hidden>
  • Date: Fri, 23 Apr 2004 21:28:25 -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. 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");


Notice that there is no fetch specification involved. EOF takes care of it all for you. The SELECT, the join the whole nine yards. Now it's obvious why this is the easiest way to get the Log objects. Why is this the best performing? Because EOF will cache the results of that relationship traversal and never perform that underlying SELECT again. As you get more comfortable with EOF you may come to see problems with that caching but in general it is the way to go. For the issues feel free to visit http://wodev.spearway.com/cgi-bin/WebObjects/WODev.

The power in WebObjects/EOF is in getting the model you define with EOModeler to do all the work. Say I had a Log and needed the CustView related to it. Then I just do log.valueForKey("customer"); Use the Model!

----
WO in philadelphia - wanna cheesesteak with that?
Please visit webobjects.meetup.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.


  • Follow-Ups:
    • Re: Fetching from related object
      • From: Randall Perry <email@hidden>
    • Re: Fetching from related object
      • From: Randall Perry <email@hidden>
    • Re: Fetching from related object
      • From: Randall Perry <email@hidden>
    • Re: Fetching from related object
      • From: Anjo Krank <email@hidden>
References: 
 >Fetching from related object (From: Randall Perry <email@hidden>)

  • Prev by Date: Re: Fetching from related object
  • Next by Date: Re: Fetching from related object
  • Previous by thread: Re: Fetching from related object
  • Next by thread: Re: Fetching from related object
  • Index(es):
    • Date
    • Thread