mdoar wrote:
>
> I'm using declarative classes for a table with a few foreign keys to
> other tables. When I look at the SQL queries I see the query to get
> all the rows of the main table and then a few extra queries for each
> row's foreign keys; all as expected. However, it seems that since I am
> not modifying any of the tables, there might be a way to have the
> secondary tables loaded once to avoid the multiple queries per row
> that is killing performance right now.
>
> Am I missing some option that already exists?

the many-to-one loads will place those entities in the session keyed to
their primary key.  when a lazyloader on a parent object fires off, it
checks the identity map first before loading.    So as long as that object
was already loaded and is strongly referenced, it wont use SQL.

Here's what is needed for that to work.

1. strongly referenced somewhere, or weak_identity_map=False on your
session.  else the object is garbage collected and SQL is required to load
it.
2. the relation is many-to-one and would use the same SQL to load as that
of a query.get().   For simple many-to-ones this always the case, but in
the case of custom primaryjoin conditions or with some inheritance
scenarios, its not.     If your many-to-one references a column on a
joined-table inheriting class, specify a custom primaryjoin that
references the primary key column(s) on the base table - you'll need the
foreign_keys argument for this too.






>
> ~Matt
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to