Esempio n. 1
0
    def setup_mappers(self):
        global Session
        Session = scoped_session(sessionmaker())

        mapper(User, users, properties={
            'addresses':relation(Address, backref='user', order_by=addresses.c.id)
        })
        mapper(Address, addresses)

        compile_mappers()
Esempio n. 2
0
    def setup_mappers(self):
        global Session
        Session = scoped_session(sessionmaker())

        mapper(User,
               users,
               properties={
                   'addresses':
                   relation(Address, backref='user', order_by=addresses.c.id)
               })
        mapper(Address, addresses)

        compile_mappers()
Esempio n. 3
0
 def test_override_get(self):
     """MapperExtension.get()
     
     x = session.query.get(5)
     
     """
     from sqlalchemy.orm.query import Query
     cache = {}
     class MyQuery(Query):
         def get(self, ident, **kwargs):
             if ident in cache:
                 return cache[ident]
             else:
                 x = super(MyQuery, self).get(ident)
                 cache[ident] = x
                 return x
                 
     session = sessionmaker(query_cls=MyQuery)()
     
     ad1 = session.query(Address).get(1)
     assert ad1 in cache.values()
Esempio n. 4
0
    def test_override_get(self):
        """MapperExtension.get()
        
        x = session.query.get(5)
        
        """
        from sqlalchemy.orm.query import Query
        cache = {}

        class MyQuery(Query):
            def get(self, ident, **kwargs):
                if ident in cache:
                    return cache[ident]
                else:
                    x = super(MyQuery, self).get(ident)
                    cache[ident] = x
                    return x

        session = sessionmaker(query_cls=MyQuery)()

        ad1 = session.query(Address).get(1)
        assert ad1 in cache.values()