[sqlalchemy] Re: Strange lazy-load query

2011-03-08 Thread Joril
On 7 Mar, 15:55, Michael Bayer mike...@zzzcomputing.com wrote:
 the left outer join means there is a lazy=False or lazy='joinedload' on the 
 relationship, or in this case since its sporadic, the parent Invoice is 
 likely being loaded with an option like joinedload(Product.vat).    The 
 options specified in Query get attached to lazy loaders later in the chain, 
 if the given joinedload() chain doesn't start from the entity being queried 
 (which is probably the case if the query uses joinedload() and not 
 joinedload_all()).

Problem solved, many thanks :)

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



Re: [sqlalchemy] Declarative Class registry ?

2011-03-08 Thread Michael Bayer
there's no registry of tables to mappers.   You'd need to track that 
yourself, or otherwise scan through all mappers (non-public attribute 
sqlalchemy.orm._mapper_registry)  looking for tables (each mapper has a 
.local_table attribute).   Note that many mappers can be created against a 
single table.

To track yourself:

from sqlalchemy.orm import mapper as _mapper
import collections

my_registry_of_tables = collections.defaultdict(set)
def mapper(cls, table=None, *arg, **kw):
my_registry_of_tables[table].add(cls)
return _mapper(cls, table, *arg, **kw)

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(mapper=mapper)



On Mar 7, 2011, at 11:51 PM, James Mills wrote:

 Hello,
 
 Given a scenario where you're using declarative_base(...) and defining classes
 
 Is there a way to ask SA what the mapper class (declarative) is for a given 
 table
 by inspecting something in metadata[table_name] ?
 
 cheers
 James
 
 
 
 -- 
 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.

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



Re: [sqlalchemy] Declarative Class registry ?

2011-03-08 Thread James Mills
On Wed, Mar 9, 2011 at 2:16 AM, Michael Bayer mike...@zzzcomputing.com wrote:
 there's no registry of tables to mappers.   You'd need to track that 
 yourself, or otherwise scan through all mappers (non-public attribute 
 sqlalchemy.orm._mapper_registry)  looking for tables (each mapper has a 
 .local_table attribute).   Note that many mappers can be created against a 
 single table.

 To track yourself:

 from sqlalchemy.orm import mapper as _mapper
 import collections

 my_registry_of_tables = collections.defaultdict(set)
 def mapper(cls, table=None, *arg, **kw):
    my_registry_of_tables[table].add(cls)
    return _mapper(cls, table, *arg, **kw)

 from sqlalchemy.ext.declarative import declarative_base
 Base = declarative_base(mapper=mapper)

Thanks Michael.

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method

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