Questions on Fetching with Conditions
Satoru Moriwaki <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have a couple of questions:
1) Is there another way to fetch row count without using the raw row
SQL or the obj.objects().count() method?
e.g.
String SQL = "select count(class_id) as count from clazz where use_id
= 1";
NSArray objects = EOUtilities.rawRowsForSQL(ec, "Clazz", SQL, null);
NSDictionary dict = (NSDictionary)objects.objectAtIndex(0);
String count = dict.objectForKey("COUNT");
or
int count = student.classes().count();
The first one, I have to hard code the SQL. The second one fetches
all of the classes to count. I do not wish to do that.
2) Is there another way to fetch "one" (limit 1) to-many relationship
entity object sorted by a certain column in ascending/decending order
without using the raw row SQL or having to fetch all of the objects
using the obj.objects() and then sort?
e.g.
String SQL = "select * from clazz where user_id = '1' order by
registration_date ASC limit 1";
....
....
..
or
NSArray classes = student.classes();
...
.. (and then sort or get the last index of objects or whatever...)
..
Thanks!
Satoru