> *** Hmmm....
>
> I still feel that I should be able to say:
>
> ads_global = p.producer.producer_category.ads
> for category in p.image_categories:
>       ads_global.filter(<category in Ad.image_categories>)
>
> and then make a random selection from the results.  I just don't know
> how to do that part in the <>.
>
> Problem is, I can't just get ads_global from the DB and then search
> through them manually.  There will simply be too many of them, and the
> SELECT will really damage performance.
>
> What I could do, assuming the above is impossible, however, is to get a
> random 10-element subset of ads_global, and manually search through
> that.  If I don't find a suitable match, I get another one, and so on.
> After N attempts, I can just give up.  It's not optimal, but it might
> have to do.
>
> So nobody is able to recommend a way in which I could implement the
> above pseudo-code?

I don't get the near-desperate attempts to avoid SQL under all circumstances 
that some people seem to fall in love to the very moment the start using a 
ORM tool. The solution is easily expressed in a single query - why do you 
strive for a different way to do it? Especially, when you know that in the 
end, SQL will be the result anyway - after all, you are using an ORM mapper.

If people want pure OO-paradigms, use a real OO-database. ZODB for example. 
But incidentially, I haven't come across one that allows for such queries to 
be expressed in an elegant way - if at all. Because the relationships between 
objects that are based on references don't allow for a canonic way to express 
arbitrary relations that base on whatever criteria one might think of. These 
are - surprise, surprise - better expressed using relational algebra. The 
foundation of RDBMSes. Things expressed naturally in one paradigm - e.g. 
inheritance - are less elegant expressed in the other. But the strategy to 
deal with this should be to switch viewpoints/paradigms.

Take a simple example: python has many functional programming concepts, e.g. 
list-comprehensions. The idiom for dealing with a classical map-filter 
situation in java, a more "pure" OO-language is (I use python to spare us the 
declariation overhead...):

res = []
for item in items:
   if some_predicate(item):
          res.append(some_mapping(item))

where the using listcomps it is the much more elegant

res = [some_mapping(item) for item in items if some_predicate(item)]

Does anybody cry foul on the second variant just because it was used in 
otherwise OO-style code? I doubt it...

I'm all for ORM to serialize ones object graphs. ACID, and natural working 
within the language object model are two of them. 

But a very important third one is also the capability to switch the paradigm, 
and view my data in a relational way. Which allows for better reporting and 
complexer queries expressed easily, and declarative. 

Please don't take this rant as a personal insult - your post is just the last 
one in a series of postings I wanted to comment on in a similar way.

My $0.02

Diez

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to