Hey Michael,

I decided it would probably be easier/faster to just write a custom
query -- the frontend is a pylons page that is used to search for
content so I want it to be as responsive as possible:

fields = [content_table.c.content_id,
                      content_table.c.type,
                      accounts.c.user_name,
                      content_table.c.status,
                      content_table.c.creation_time,
                      content_table.c.title,
                      content_table.c.uuid,
                      content_leaf.c.reviewed,
                      content_leaf.c.flagged]

            where = [content_table.c.account_id ==
accounts.c.account_id]

            if c.content_title:

where.append(content_table.c.title.like(c.content_title))

yada yada yada...


            s = select(fields, whereclause=and_(*where),
from_obj=[outerjoin(content_table,
content_leaf)]).order_by(content_table.c.content_id.desc())
            rp = Session.execute(s)

This works pretty well and I think from the DB side, this is about as
fast as it can get since I'm pulling back the minimum amount of data
with a simple query.

thx

Matt

On Dec 30, 5:51 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Dec 30, 2007, at 8:01 PM, Matt wrote:
>
>
>
>
>
> > Yeah, I didn't include the whole Content mapper, here are the
> > polymorphic params for that mapper:
>
> > polymorphic_on=content_table.c.type, polymorphic_identity='content'
>
> > And ContentLeaf:
>
> > mapper(ContentLeaf, content_leaf,
> >           properties = {
> >            '_copyright': content_leaf.c.copyright,'copyright' :
> > synonym('_copyright'),
> >            '_grid     ': content_leaf.c.grid,'grid' :
> > synonym('_grid'),
> >            '_gtin'     : content_leaf.c.gtin,'gtin' :
> > synonym('_gtin'),
> >            '_iswc'     : content_leaf.c.iswc,'iswc' :
> > synonym('_iswc'),
> >            '_isan'     : content_leaf.c.isan,'isan' :
> > synonym('_isan'),
> >            '_isrc'     : content_leaf.c.isrc,'isrc' :
> > synonym('_isrc'),
> >            '_reviewed' : content_leaf.c.reviewed,'reviewed' :
> > synonym('_reviewed'),
> >            '_flagged'  : content_leaf.c.flagged,'flagged' :
> > synonym('_flagged'),
> >            '_ingestion_type':
> > content_leaf.c.ingestion_type,'ingestion_type' :
> > synonym('_ingestion_type'),
> >           },
> >           inherits             = cm,
> >           polymorphic_on       = content_table.c.type,
> >           polymorphic_identity ='leaf')
>
> > So, loading polymorphically is working for me.
>
> > So maybe I can do something like:
>
> > q =
> > Session
> > .query
> > (Content
> > ).add_entity(Account).select_from(content_table.outerjoin(accounts))
>
> > To get the account?
>
> heres a random guess at what might make this actually work (its a  
> workaround).  Make the regular mappers, with the eagerload to  
> 'accounts', and select_table.  Then, after you make your mappers, say  
> this:
>
> compile_mappers()
> class_mapper(Content).get_select_mapper().add_property('accounts',  
> Account, lazy=False)
>
> that might be all thats needed here.  basically just sticking the  
> property on the "surrogate" mapper, which is the mapper mapped to your  
> select_table.
>
> otherwise, same idea is just make a second mapper against the join  
> using non_primary=True.
--~--~---------~--~----~------------~-------~--~----~
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