All pastes #516506 Raw Edit

Unnamed

public python v1 · immutable
#516506 ·published 2007-05-28 18:55 UTC
rendered paste body
from elixir import metadata, objectstore, Entity, using_mapper_optionsfrom elixir import has_field, belongs_to, has_many, Unicodefrom sqlalchemy import MapperExtension, EXT_PASSclass TestMapperExtension(MapperExtension):        def append_result(self, mapper, selectcontext, row, instance, identitykey, result, isnew):                instance._magic_method()             return EXT_PASS    class Test(Entity):        has_field('text', Unicode(255))    has_many('data', of_kind='TestData')    #using_mapper_options(extension=TestMapperExtension())        def _magic_method(self):        print self.text        for item in self.data:            print " ", item.textclass TestData(Entity):        has_field('text', Unicode(255))    belongs_to('parent', of_kind='Test')metadata.connect('sqlite:///:memory:')metadata.create_all()    t = Test(text="a", data=[TestData(text="b"), TestData(text="c")])objectstore.flush()t._magic_method()del tobjectstore.clear()t = Test.select()[0]t._magic_method()