The name of the property from the mapper perspective is "name". That's the
contract of declarative:
class MyClass(some_declarative_base):
__tablename__ = 'j'
x = Column(Integer, key='z')
y = Column('p', Integer, key='w')
==
t = Table('j', metadata,
Column('x', Integer, key='z'),
Column('p', Integer, key='w')
)
mapper(MyClass, t, properties={
'x':t.c.z,
'y':t.c.w
})
if you were just using mapper(), then Column.key is what specifies the
attribute names in the mapping.
To go from "name_key", you could say
class_mapper(MyClass)._columntoproperty[t.c.name_key].
On Jan 12, 2011, at 3:26 PM, Eric Lemoine wrote:
> Hi
>
> Mapper.get_property doesn't behave as I'd expect it to, so I'd just
> like to know if my understanding is incorrect. In the following
> testcase I'd expect the first test to pass and the second to fail, but
> I get the opposite. Thanks a lot.
>
>
>
> from sqlalchemy import Column, Integer, String
> from sqlalchemy.orm.util import class_mapper
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.exc import InvalidRequestError
>
> Base = declarative_base()
>
> class User(Base):
> __tablename__ = 'users'
> id = Column(Integer, primary_key=True)
> name = Column(String, key='name_key')
>
> try:
> class_mapper(User).get_property('name_key')
> except InvalidRequestError:
> print "error 1"
>
> try:
> class_mapper(User).get_property('name')
> except InvalidRequestError:
> print "error 2"
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : [email protected]
> http://www.camptocamp.com
>
> --
> 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.
>
--
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.