On Wednesday 24 September 2008 14:14:31 Christoph Zwerschke wrote:
> But (in the default project template) the classes are mapped to the
> table with a session-aware mapper, so instead of
>
> session.query(Types.Ship).filter_by(shipid=args['shipid'])
>
> you can just write
>
> Types.Ship.query.filter_by(...)
It seems what we have here is a documentation problem. Here's a revised test
script:
=======
import sqlalchemy
from sqlalchemy.orm import mapper
# from turbogears.database import mapper
from turbogears.database import metadata
class Package(object): pass
package_table = sqlalchemy.Table(
'package',
metadata,
autoload=True,
schema='public')
mapper(Package, package_table)
print Package.query
=======
If I run "tg-admin shell" and paste the above into it, I get:
>>> Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: type object 'Package' has no attribute 'query'
If I switch the import lines to:
# from sqlalchemy.orm import mapper
from turbogears.database import mapper
and try again, I get:
>>> <sqlalchemy.orm.scoping.query object at 0x1d8a910>
In the documentation, it says:
The mapper function from turbogears.database is identical with
SQLAlchemy's contextual mapper() if you use SQLAlchemy >= 0.4, and
something similar if you use SQLAlchemy < 0.4
but I would posit that it's not identical, at least in that you can't use SA's
instead of TG's and hope for it to work.
--
Kirk Strauser
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---