Re: Whats the recommended way for cross-object information inquiry?
Re: Whats the recommended way for cross-object information inquiry?
- Subject: Re: Whats the recommended way for cross-object information inquiry?
- From: Jonathan Rochkind <email@hidden>
- Date: Wed, 10 Mar 2004 11:14:18 -0600
Sure. There are a number of ways you could do it, but the very simple
way that's been working well for me:
Add an attribute called "derivedCount" to the model for the entity
who's table you're going to be querrying against. This attribute
should be a derived/defined attribute (rather than a column
attribute), who's definition is "count(*)". It's important that this
attribute is NOT a class property!
Now, after you've built your qualify, and built your fetch
specification, just call:
fetchSpecification.setRawRowKeyPaths( new NSArray("derivedCount"));
When you execute the fetch spec, you'll get back an array with a
single element. That element will be an NSDictionary (raw row) with a
single key/value. That value will be your count.
In general, if you want unusual (for EOF) SQL in the "select" clause,
adding defined/dervied non-class-property EOAttributes, with the form
you want, is often useful. Of course, you can only get raw rows with
these non-class-property attributes.
Theoretically, instead of having to define this attribute in your
static model, you could dynamically add it to any arbitrary entity at
run-time, when needed. But I've been reluctant to do this, since
nowhere is it documented what lock()s you should take out before
modifying an EOModel that might be in use. Should be fairly safe
anyway, since you're just adding a non-class property, but I just add
the derived attribute to my actual static model for entities where
it's needed, works fine for me.
--Jonathan
At 10:24 AM -0600 3/10/04, Jonathan 'Wolf' Rentzsch wrote:
Jonathan Rochkind, email@hidden, wrote:
Counting rows, I know how to do with straight qualifiers (for a fetch
spec that will return raw rows).
Sounds interesting. Can you share it with us?
| Jonathan 'Wolf' Rentzsch http://rentzsch.com
| Red Shed Software http://redshed.net
| "better" necessarily means "different"
_______________________________________________
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.