alex bodnaru wrote:
> i'd like to have my entities inherit from a non-entity object, in
> order to supply them some common functionality.
Alternatively, you could use multiple-inheritance, and place
your shared functionality in a mix-in base class. I do this
occasionally:
class HelloMixIn(object):
def say_hello(self):
print 'Hello, %s' % self.name
class Person(Entity, GreetingMixIn):
name = Field(String(64))
p = Person(name='Jonathan')
p.say_hello()
Its easy enough, and doesn't require any special monkeying around
with defining your own base class.
> to my understanding, EntityMeta should be the name of my solution,
> but i'd appreciate a pointer to an example of it's usage.
Well, `EntityMeta` is the metaclass that is required for all Elixir
classes to function properly. If you want to define your own base
class, you'll have to define one like so:
class MySpecialEntity(object):
__metaclass__ = EntityMeta
This base class can then be used in place of `Entity` wherever you
like. However, keep in mind that there is some functionality on the
`Entity` class that you might lose. If you're going to be monkeying
around with this kind of thing, I'd strongly recommend looking at
the Elixir source so you understand the `Entity` class a bit better.
> on another level: could the base class include some actual fields,
> to be common to all classes, but without entity inheritance
> semantics?
At this point, I don't believe that this is possible, but I don't
recall why off the top of my head. You might just consider using
an alternative form of inheritance: concrete. In this method of
inheritance, all of the shared columns are copied to inherited
tables:
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance_concrete
Best of luck.
--
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
-~----------~----~----~----~------~----~------~--~---