thanks jonathan for your prompt answer.
Jonathan LaCour wrote: > 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. > i like this solution, and it may even be extensible. thanks a lot. >> 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. > ok, i have to consider those, of course. >> 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 > indeed, the concrete inheritance should serve this purpose, but: 1. the fields i wanted to have in every table are some meta-information, like updator/creator id and last modify time, which have no need to be in the primary key. 2. those fields should be only part of one entity, which others may inherit from. but could one inheritance be concrete, and the other be multitable join? all the best, alex > 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 -~----------~----~----~----~------~----~------~--~---
