isn't polymorphic_union( { 'a': select..., 'b': select... }, 'kind' ) 
working in your case?

On Wednesday 21 March 2007 21:37:47 Toshio Kuratomi wrote:
> Hi guys.
>
> I'm using sqlalchemy with TurboGears.  The code for my project is
> GPL, so if you need access to more source just let me know:
>
> I was successfully using the following definition of a
> polymorphic_union in 0.3.4::
>
> '''
> collectionJoin = polymorphic_union (
>         {'b' : select((CollectionTable.join(
>             BranchTable, CollectionTable.c.id ==
> BranchTable.c.collectionid),
>             column("'b'").label('kind'))),
>          'c' : select((CollectionTable,
> column("'c'").label('kind')), not_(CollectionTable.c.id.in_(select(
>                  (CollectionTable.c.id,),
>                  CollectionTable.c.id ==
> BranchTable.c.collectionid) )))
>          },
>         None
>         )
> '''
>
> In 0.3.5, this gives me errors.  Inspecting the SQL, it looks like
> I'm getting this kind of select now::
>   SELECT collection.id, "\'c\'" AS kind \nFROM collection
>
> which isn't what I want.  I want something more like this::
>   SELECT collection.id, 'c' AS kind \nFROM collection
>
> I browse the docs and find that literal() is what I want.  I try::
> '''
> select((CollectionTable, literal('c').label('kind')),
>              not_(CollectionTable.c.id.in_(select(
>                  (CollectionTable.c.id,),
>                  CollectionTable.c.id ==
> BranchTable.c.collectionid) )))
> '''
>
> which works fine as a bare statement.  Now I plug this into my
> polymorphic union::
> '''
> collectionJoin = polymorphic_union (
>         {'b' : select((CollectionTable.join(
>             BranchTable, CollectionTable.c.id ==
> BranchTable.c.collectionid),
>             literal('b').label('kind'))),
>          'c' : select((CollectionTable,
> literal('c').label('kind')), not_(CollectionTable.c.id.in_(select(
>                  (CollectionTable.c.id,),
>                  CollectionTable.c.id ==
> BranchTable.c.collectionid) )))
>          },
>         None
>         )
> '''
>
> And now I'm getting a different error::
> '''
> Traceback (most recent call last):
>   File
> "/var/www/repo/vanilla-fedora-packagedb/pkgdb/start-pkgdb.py", line
> 25, in ?
>     from pkgdb.controllers import Root
>   File "/var/www/repo/vanilla-fedora-packagedb/pkgdb/pkgdb/
> controllers.py", line 7, in ?
>     from pkgdb import model
>   File
> "/var/www/repo/vanilla-fedora-packagedb/pkgdb/pkgdb/model.py", line
> 222, in ?
>     None
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/util.py",
> line 47, in polymorphic_union
>     for c in table.c:
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 779, in <lambda>
>     c = property(lambda s:s._get_exported_attribute('_columns'))
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 776, in _get_exported_attribute
>     self._export_columns()
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 801, in _export_columns
>     export = self._exportable_columns()
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 1226, in _exportable_columns
>     return self.selectable.columns
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 778, in <lambda>
>     columns = property(lambda
> s:s._get_exported_attribute('_columns')) File
> "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 776, in
> _get_exported_attribute
>     self._export_columns()
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line
> 815, in _export_columns
>     for ci in cp.orig_set:
> AttributeError: '_BindParamClause' object has no attribute
> 'orig_set' '''
>
> Any ideas on how I should construct my polymorphic_union?
>
> Thanks,
> -Toshio
>
>
> 


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to