On Oct 3, 6:05 pm, Brett <[EMAIL PROTECTED]> wrote:
> The following code give an error about an ambiguous column on the
> order_by.  This can easily be fixed by changing the order by column to
> 'anything.code' but I would assume that since the query will return
> objects of type Anything then it would assume anything.code
>
> --------------------------------
> from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base
>
> Base = declarative_base()
>
> class Something(Base):
>     __tablename__ = 'something'
>     __mapper_args__ = {'order_by': 'code'}
>     id = Column(Integer, primary_key=True)
>     code = Column(String)
>
> class Anything(Base):
>     __tablename__ = 'anything'
>     __mapper_args__ = {'order_by': 'code'}
>     id = Column(Integer, primary_key=True)
>     code = Column(String)
>     something_id = Column(Integer, ForeignKey('something.id'))
>     somethings = relation(Something)

specify the mapper args at the end, saying __mapper_args__ =
{'order_by':code}.  SQLA uses objects for all SQL constructs so that
it would know the column is in fact the one attached to Anything or
Something.  It never interprets the contents of strings, which can
have any expression in them, not just the string name of a local
column.
--~--~---------~--~----~------------~-------~--~----~
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