Okay, I just committed the first preliminary version of the event
handling hooks for Elixir as an extension. Here is a quick sample:
from elixir import *
from elixir.ext.events import *
class Person(Entity):
has_field('name', Unicode)
responds_to_events()
@before_insert
def test(self):
print '-' * 80
print self.name
print '-' * 80
Again, the only reason that the "responds_to_events" statement is needed
is to insert the proper mapper extension into the entity, since the
class, table, mapper, etc. don't exist at the time that the method is
decorated.
I don't personally mind the requirement, however we could avoid it by
simply having the events module add its mapper extension into the global
mapper extensions on import, like so:
from sqlalchemy.orm.mapper import global_extensions
global_extensions.append(event_mapper_extension)
Would you like me to make this change, or keep it as it is? The
downside to such an approach is that this mapper extension would be
added onto every single mapper in the process, even if just one Entity
is using events. It should be minor overhead, but its still something to
consider.
I am open to other suggestions on how to solve this :)
--
Jonathan LaCour
http://cleverdevil.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---