def get_by(self, *args, **params):
"""returns a single object instance based on the given key/value criterion.
this is either the first value in the result list, or None if the list is
empty.
the keys are mapped to property or column names mapped by this mapper's Table, and the values
are coerced into a WHERE clause separated by AND operators. If the local property/column
names dont contain the key, a search will be performed against this mapper's immediate
list of relations as well, forming the appropriate join conditions if a matching property
is located.
e.g. u = usermapper.get_by(user_name = 'fred')
"""
x = self.select_whereclause(self._by_clause(*args, **params), limit=1)
if len(x):
return x[0]
else:
return None
评论列表
文章目录