Chapter A.11. Changing Calls to byName Methods

SQLObject defines a number of useful methods on your classes such as select, to retrieve many objects based on query parameters, and get, to retrieve a single object based on its primary key. SQLAlchemy gives you those class methods.

For every column that you declare as an “alternateID” in SQLObject, SQLObject creates a class method called byColumnName. The idiom used in SQLAlchemy is different: There is a class method called get_by and you pass in a keyword parameter to retrieve a specific instance by that alternate ID. You have two options:

  1. You can change all the calls to byColumnName. In SQLObject you say obj = YourClass.byColumnName(value_to_find). In SQLAlchemy, you say obj = YourClass.get_by(columnName ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.