ill look later, but the "key" option in Column is weakly tested; the
polymorph thing plays with column names heavily so its not surprising it
doesnt work.  youre better off using a property:

m = mapper (.... , properties = {
    'primaryLanguage': mytable.c.primary_language
    }
)


Vasily Sulatskov wrote:
> Hello,
>
> I tried to add alias to column in polymorph2.py in examples/polymorph
> and it doesn't work.
>
> Here is what I changed in an example (full example is attached):
>
> 25c25
> <    Column('primary_language', String(50)),
> ---
>>    Column('primary_language', String(50), key='primaryLanguage'),
> 72c72
> <                     engineers.c.primary_language,
> ---
>>                     engineers.c.primaryLanguage,
>
> When run modified example produses following traceback:
> Traceback (most recent call last):
>   File
> "C:\home\Vasily\sqlalchemy\sqlalchemy\examples\polymorph\polymorph3.py",
> line 114, in ?
>     c = Company.get(1)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 245, in get
>     return self.query.get(*ident, **kwargs)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\query.py", line
> 42, in get
>     return self._get(key, ident, **kwargs)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\query.py", line
> 204, in _get
>     return self._select_statement(statement, params=params,
> populate_existing=reload)[0]
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\query.py", line
> 212, in _select_statement
>     return self.instances(statement.execute(**params), **kwargs)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\query.py", line
> 167, in instances
>     return self.mapper.instances(session=self.session, *args, **kwargs)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 388, in instances
>     self._instance(session, row, imap, result,
> populate_existing=populate_existing)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 737, in _instance
>     self.populate_instance(session, instance, row, identitykey, imap,
> isnew)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 760, in populate_instance
>     prop.execute(session, instance, row, identitykey, imap, isnew)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\properties.py",
> line 807, in execute
>     self._instance(session, row, imap, result_list)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\properties.py",
> line 837, in _instance
>     return self.mapper._instance(session, row, imap, result_list)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 736, in _instance
>     if self.extension.populate_instance(self, session, instance, row,
> identitykey, imap, isnew) is EXT_PASS:
>   File
> "C:\home\Vasily\sqlalchemy\sqlalchemy\examples\polymorph\polymorph3.py",
> line 91, in populate_instance
>     Engineer.mapper.populate_instance(session, instance, row, identitykey,
> imap, isnew, frommapper=mapper)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 757, in populate_instance
>     row = frommapper.translate_row(self, row)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\mapper.py", line
> 752, in translate_row
>     newrow[c] = newrow[c.key]
>   File "C:\Python24\Lib\site-packages\sqlalchemy\util.py", line 189, in
> __getitem__
>     return self.decorate[key]
>   File "C:\Python24\Lib\site-packages\sqlalchemy\mapping\properties.py",
> line 816, in __getitem__
>     return self.row[key]
>   File "C:\Python24\Lib\site-packages\sqlalchemy\engine.py", line 867, in
> __getitem__
>     return self.__parent._get_col(self.__row, key)
>   File "C:\Python24\Lib\site-packages\sqlalchemy\engine.py", line 811, in
> _get_col
>     rec = self.props[key.lower()]
> KeyError: 'primarylanguage'
>
> Can anyone explain, am I doing something wrong? Or is it a bug in
> sqlalchemy?
>
>
> --
> Best regards,
>  Vasily                          mailto:[EMAIL PROTECTED]



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to