Thanks for the answers.

I implemented message loading with find_members() kind of method, as
shown in the documentation link you gave, and it got twice as fast.
But it's still nowhere near the speed without the ORM. Makes me a bit
sad, as i really liked the ORM system. Maybe if i remove any automatic
relations and manually get them it would be faster.

Or maybe i should use ORM normally, but work without it on
bottlenecks.

--
K

On Apr 2, 8:20 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> sqlalchemy relationships are currently only "fully" loading - meaning
> you cant directly filter on an instances collection attribute.
>
> however you can construct your own query based on the relationship
> and use that, and theres plenty of tools to make that easy.
>
> such as, if you set up a bi-directional relationship:
>
> class A(object):pass
> class B(object):pass
>
> mapper(B, b_table)
> mapper(A, a_table, properties={
>         "b_collection" : relation(A, secondary=a_to_b_table,
> backref="a_collection")
>
> })
>
> if you load an instance of "A":
>
> mya = session.query(A).select(a.id=7)
>
> you can query the "B"s on an "A" via the backref:
>
> result = session.query(B).filter_by(a_collection=mya).filter
> (A.c.somecriterion=='foo').list()
>
> theres also some patterns for dealing with large collections at:
>
> http://www.sqlalchemy.org/docs/
> adv_datamapping.html#advdatamapping_properties_working
>
> On Apr 2, 2007, at 7:44 AM, Kaali wrote:
>
>
>
> > Can i use ORM many-to-many relations and filter SQL -side? If i can't,
> > can you give me an example on how i should use many-to-many relations
> > with filtering in SQLAlchemy?
>
> > --
> > K
>
> > On Apr 2, 1:36 pm, svilen <[EMAIL PROTECTED]> wrote:
> >>> After getting the results, i will filter them with Python filters,
> >>> as i don't know how to filter many-to-many queries directly.
>
> >>> Should i somehow make custom queries that handles many-to-many
> >>> relationships etc. or is there something else i'm missing that
> >>> makes the system slow? I have ran the bench with MySQL and
> >>> PostgreSQL engines, the result is the same. When running with a
> >>> profiler, at least ~90% of the time is taken by SQLAlchemy.
>
> >> one general suggestion, try to move the filtering on the sql side;
> >> thus u'll have less data transferred then instantiated then
> >> filtered - which is probably eating most of the time.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to