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: David Griffith <email@hidden>
- Date: Tue, 09 Mar 2004 23:26:54 +0100
> Dear List,
>
> since I am still new to WO, I am wondering a lot about the
> "recommended" way for doing things. And this is where code examples
> seem to fail for me. Lots of people say "read the example code" but
> this approach almost always lacks the "Why?"s and you don't get a feel
> for how the best solution for the design would be and why. All you get
> is: it's working this way. Not: this is the most elegant way to do it
> and besides it goes nicely with the design of WO.
>
> --- Problem:
> I've got a bunch of objects with relations. Now I want to present a
> kind of semi-deep list into the top objects and their relations where
> the relations meet a certain criteria. Suppose the top objects
> represent households, the related objects are persons and I want to
> select only those that are born in a certain year. Suppose there are
> not a lot of objects, so I want to specify a list of selectable years,
> since not every year has a result and I want the user to always get a
> result.
>
> What I want to do is, get through all the persons and compile a list of
> birthdates that are selectable as search criteria. So, how to do it?
>
> My knowledge of WO from my reading so far would tell me: Fetch all
> households, repeat through them, repeat through their persons, take
> each birthdate and put it in a list if it is not already there. That
> means, WO has to load nearly all the objects from the DB
I think that's basically what I'd do - if you only want to list the years
for the people that have a birthdate in that year, you are really going to
have to step through every record.
Otherwise, you could use a fetch spec to get the people that had birthdates
between one date and another - then remove duplicates from the list.
If people are related to households then you could have currentHousehold and
currentPerson. You would need an array of households, from a fetch spec I
imagine. Then you could loop through the objects in the households array,
asking each one for its currentHousehold.people() which will give you an
array of the people in that household. You could use an EOQualifier to
filter the array by your criteria but you would still have to remove
duplicates. Or you could step through the people one at a time using
currentPerson and only add the year if it's appropriate and isn't already in
the list of years.
These are just a few suggestions, I'm sure you'll get many more.
I wouldn't recommend the SQL raw fetch approach. You really don't need to
do that - WO does most of that stuff for you.
>
> My knowledge of my DB tables would lead me to a simple SQL statement
> like SELECT YEAR, count(*) FROM PERSONS_TABLE GROUP BY YEAR ORDER BY
> YEAR; I only had to figure out how to do a raw SQL statement and get
> the values in an NSArray so I can use a WORepetition. But this leaves
> me with table-dependent knowledge inside my Java source code.
>
> Now... what is the recommended way of doing this? Object traversal and
> compiling the list for yourself or raw SQL and converting the results?
> Or is there a third much more WO-design-like manner for solving this?
>
> Your comments, hints and help are very welcome. As always. ;-)
>
> Best regards,
> Magnus
>
>
> ________________________________________________________________________
> __________
> Magnus Rembold HOCHSCHULE F\R GESTALTUNG UND KUNST Z\RICH
> Dozent IT-Technologien University of Applied Sciences and Arts Zurich
> School of Art and Design Zurich
> Fon +41 43 446 3256
> Fax +41 43 446 4587 Ausstellungsstrasse 60
> http://interaction.hgkz.ch CH-8031 Z|rich
> _______________________________________________
> 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.