A.11. Changing Calls to byName MethodsSQLObject 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:
class Products(ActiveMapper): class mapping: productCode = column(String(20), unique=True) @classmethod def byProductCode(cls, code): return cls.get_by(productCode=code) |