Usage

The ORM base class is available as pyramid_sqlalchemy.meta.BaseObject and can be included directly:

from pyramid_sqlalchemy import BaseObject

class Account(BaseObject):
    __tablename__ = 'account'
    # Define your columns and methods here.

When you need to build a query you can use the pyramid_sqlalchemy.Session session factory.

from pyramid_sqlalchemy import Session

account = Session.query(Account).first()

When writing methods for a model in a you can also use sqlalchemy.orm.session.object_session() to get the current session for the object.

from sqlalchemy.orm import object_session

class Account(BaseObject):
    def favourites(self):
        """Return all the recent favourite articles."""
        session = object_session(self)
        return session.query(Article).all()