On 5/19/06, Robin Haswell <[EMAIL PROTECTED]> wrote:

Hey there

I have item in my model which have tens of thousands of RelatedJoin
members. In the example:

class A(SQLObject):
        bees = RelatedJoin("B")

class B(SQLObject):
        ayes = RelatedJoin("A")


Say len(A.get(1).bees) > 10,000, and "obj = A.get(1)"

Accessing obj.bees in any way at all causes SO to immediately select
every single B that belongs to A - with 10,000 individual queries!! And
worse, afterwards it keeps them all in *memory* !! Anyway this is
unacceptable.

So..

I was wondering if someone could help me with my two problems:

1. I need to be able to select each obj.bees in turn, process it, and
move on. This would be acceptable

I remenber the select will fetch one at a time

2. I want to be able to do "bob = B.get(x)", work on bob, then remove
bob from the memory. Performing "del bob" doesn't work - if I enable
debugging and do "bob = B.get(1); del bob; bob = B.get (1)" only one
query is performed.

no idea on that one

I think the solution is to get obj.bees as a SelectResults object - that
way I can perform slice operations to get the data I need.

actually if u slice it into the db the equivalent of a sql LIMIT is an overloaded []
obj.select(...)[:10] if I recall correctly

However I
have no idea how to do this - I can't seem to get SO to reference the
"a_b" table, and SO documentation is a bit lacking.

This is one of the problems SO has, have you try with table.q you may get a reference to it from there.

If 1) and 2) can't be solved, could anyone tell me how to get a regular
MySQLdb cursor from turbogears? I can do it all manually but not with
A._connection.query*.

well you could always go directly to the driver, ignoring SO entirely, it's a hack but I don't think TG will complain if you modify the db directly

Thanks a lot to anyone who can help :)

Regards

-Rob
 

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to