you have to get the select() syntax right:

BillingInfo = relation('BillingInfo',
                           
primaryjoin="and_(Invoice.pay2addrid==BillingInfo.pay2addrid,Invoice.customer==
select([Customer.customer]).where(Customer.xrscustid==BillingInfo.xrscustid))")





Kirk Strauser wrote:
>
> On Thursday 30 July 2009 01:31:21 pm Michael Bayer wrote:
>
>> oh, its the string.  OK so dont do ForeignKeyConstraint, but definitely
>> add to the Invoice.BillingInfo relation() all the information needed
>> within the primaryjoin to select the correct row.   seems like it would
>> be
>> (pseudocode) "invoice.pay2addrid=billing.pay2addrid AND
>> invoice.custinfo=select(customer.stringname).where(customer.id==billing.cus
>>tid)". The subquery should work and I don't see another way to get around
>> that.
>
> Going down that road, I tried:
>
> class Invoice(Base):
>     __tablename__ = 'invoice'
>     __table_args__ = dict(schema='fro')
>
>     # Each invoice has a unique invid
>     invid = Column(Integer, primary_key=True)
>
>     # This is the name of the customer on this invoice
>     customer = Column('xrscust', String(10),
> ForeignKey('fro.xrscust.xrscust'))
>
>     # Some customers have multiple payment addresses, so point to the
>     # one used for this specific invoice
>     pay2addrid = Column(Integer, ForeignKey('fro.bllginfo.pay2addrid'))
>
>     BillingInfo = relation('BillingInfo',
>                            
> primaryjoin="and_(Invoice.pay2addrid==BillingInfo.pay2addrid,Invoice.customer==select(Customer.customer).where(Customer.xrscustid==BillingInfo.xrscustid))")
>
> but ended up with:
>
> $ ./satest.py
> Traceback (most recent call last):
>   File "./satest.py", line 67, in <module>
>     invoices = session.query(Invoice)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/session.py",
> line 895, in query
>     return self._query_cls(entities, self, **kwargs)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py",
> line 91, in __init__
>     self._set_entities(entities)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py",
> line 100, in _set_entities
>     self.__setup_aliasizers(self._entities)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py",
> line 114, in __setup_aliasizers
>     mapper, selectable, is_aliased_class = _entity_info(entity)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/util.py",
> line 492, in _entity_info
>     mapper = class_mapper(entity, compile)
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/util.py",
> line 567, in class_mapper
>     mapper = mapper.compile()
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py",
> line 658, in compile
>     mapper._post_configure_properties()
>   File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py",
> line 687, in _post_configure_properties
>     prop.init()
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/interfaces.py",
> line 408, in init
>     self.do_init()
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/properties.py",
> line 712, in do_init
>     self._process_dependent_arguments()
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/properties.py",
> line 739, in _process_dependent_arguments
>     setattr(self, attr, getattr(self, attr)())
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/ext/declarative.py",
> line 596, in return_cls
>     x = eval(arg, globals(), d)
>   File "<string>", line 1, in <module>
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/sql/expression.py",
> line 246, in select
>     s = Select(columns, whereclause=whereclause, from_obj=from_obj,
> **kwargs)
>   File
> "/usr/local/lib/python2.6/dist-packages/sqlalchemy/sql/expression.py",
> line 3239, in __init__
>     [_literal_as_column(c) for c in columns]
> TypeError: 'Column' object is not iterable
>
>
> Any idea where I might start digging into that?
> --
> Kirk Strauser
>
> >
>


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