• 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: Sort Ordering while using relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort Ordering while using relationships


  • Subject: Re: Sort Ordering while using relationships
  • From: David Neumann <email@hidden>
  • Date: Fri, 9 May 2003 20:58:18 -0500

To sort something in the DB, it needs to be in the SELECT for the fetch. When you fetch EOs, the select is just for that EO's mapped columns. Prefetching the relationship doesn't help since that's a separate fetch.

So if this is important to you, I'd recommend to doing a raw row fetch. You can still use any EOQualifiers you like. I'm not saying send your own raw SQL. Just instruct your fetch spec to fetch rows rather than EOs. When you fetch rows, you can tell the fetch spec exactly what attributes you want and none of those you don't. In this case you want probably most if not all attributes of Entity A and at least one attribute from Entity B (the one you're sorting on).

Assuming a fetch rooted on Movie where you want it sorted by studio name and you want this sorting done by the DB. I assume a mutable array and the fetch spec already exist and its set for raw row fetch...

arr.addObject("title");
arr.addObject("movieID");
arr.addObject("rating");
arr.addObject("studio.name");
fs.setRawRowKeyPaths(arr);
NSArray rows = ec.objectsWithFetchSpecification(fs);


What's neat about this is that EOF will automatically create the table list and join for the destination table. The rows you get back will have keys equal to that used in the raw row key paths setting. That is: imagine a dictionary that looked like this:


{
	title = "Raiders of the Lost Ark";
	movieID = 56;
	rating = "PG";
	studio.name = "Paramount Pictures";
}

Values will be of the same type as you expect from the EOModel. Numbers will be numbers, dates will be timestamps and so forth.

In this example, I pulled back PKs too on theory that you might want to convert the rows to EOs at some point in the future.

This beats raw SQL since you get the benefit of some relational fun but w/o complete hardcoding yourself to DB specific join semantics.

One note... you might want too add some extra rels to your model for fetches like this and mark them as Left Outer rather than Inner. In the above example, a Inner join to Studio from Movie would not return any Movies that had no Studio. This might be mysterious to you because merely dropping the keypath that crossed the studio rel would suddenly return more rows for the same qualifier. With a Left Outer join and a null studio FK for "Raiders of the Lost Ark" the returned dict for that row would have looked like:

{
	title = "Raiders of the Lost Ark";
	movieID = 56;
	rating = "PG";
	studio.name = <THE EONULL VALUE>;
}

d



On Friday, May 9, 2003, at 12:10 PM, Anurag Khare wrote:

Hi !

In my EOModel EntityA is having a to-many relationship with EntityB. I am able to fetch records from EntityB through relationship speicfying fetch spec containing Relationship.EntityBAttribute. But in SortOrdering option when I specify Relationship.EntityBAttribute, it dooesn't display ordered objects. It looks as if I haven't used any SortOrdering option in the EOModel.

I am definitely missing something. Or is it that I can not use EntityBAttribute to sort order objects?

Thanks
Anurag

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Sort Ordering while using relationships (From: "Anurag Khare" <email@hidden>)

  • Prev by Date: Re: Outer Join Question (more)
  • Next by Date: char set (not yet)
  • Previous by thread: Re: Sort Ordering while using relationships
  • Next by thread: Retrieving selected value from WOPopUpButton
  • Index(es):
    • Date
    • Thread