| 20 | | |
| 21 | | class Entity(object): |
| 22 | | ''' |
| 23 | | The base class for all entities |
| 24 | | |
| 25 | | All Elixir model objects should inherit from this class. Statements can |
| 26 | | appear within the body of the definition of an entity to define its |
| 27 | | fields, relationships, and other options. |
| 28 | | |
| 29 | | Here is an example: |
| 30 | | |
| 31 | | :: |
| 32 | | |
| 33 | | class Person(Entity): |
| 34 | | has_field('name', Unicode(128)) |
| 35 | | has_field('birthdate', DateTime, default=datetime.now) |
| 36 | | |
| 37 | | Please note, that if you don't specify any primary keys, Elixir will |
| 38 | | automatically create one called ``id``. |
| 39 | | |
| 40 | | For further information, please refer to the provided examples or |
| 41 | | tutorial. |
| 42 | | ''' |
| 43 | | |
| 44 | | class __metaclass__(type): |
| 45 | | def __init__(cls, name, bases, dict_): |
| 46 | | # only process subclasses of Entity, not Entity itself |
| 47 | | if bases[0] is object: |
| 48 | | return |
| 49 | | |
| 50 | | # create the entity descriptor |
| 51 | | desc = cls._descriptor = EntityDescriptor(cls) |
| 52 | | EntityDescriptor.current = desc |
| 53 | | |
| 54 | | # process statements |
| 55 | | Statement.process(cls) |
| 56 | | |
| 57 | | # setup misc options here (like tablename etc.) |
| 58 | | desc.setup_options() |
| 59 | | |
| 60 | | # create table & assign (empty) mapper |
| 61 | | desc.setup() |
| 62 | | |
| 63 | | # try to setup all uninitialized relationships |
| 64 | | EntityDescriptor.setup_relationships() |
| 93 | | self.autoload = None |
| 94 | | self.tablename = None |
| 95 | | self.shortnames = False |
| 96 | | self.auto_primarykey = True |
| 97 | | self.order_by = None |
| 98 | | self.mapper_options = dict() |
| 99 | | self.table_options = dict() |
| | 51 | |
| | 52 | for option in ('autoload', 'shortnames', 'auto_primarykey'): |
| | 53 | setattr(self, option, options_defaults[option]) |
| | 54 | |
| | 55 | for option_dict in ('mapper_options', 'table_options'): |
| | 56 | setattr(self, option_dict, options_defaults[option_dict].copy()) |
| | 217 | |
| | 218 | class Entity(object): |
| | 219 | ''' |
| | 220 | The base class for all entities |
| | 221 | |
| | 222 | All Elixir model objects should inherit from this class. Statements can |
| | 223 | appear within the body of the definition of an entity to define its |
| | 224 | fields, relationships, and other options. |
| | 225 | |
| | 226 | Here is an example: |
| | 227 | |
| | 228 | :: |
| | 229 | |
| | 230 | class Person(Entity): |
| | 231 | has_field('name', Unicode(128)) |
| | 232 | has_field('birthdate', DateTime, default=datetime.now) |
| | 233 | |
| | 234 | Please note, that if you don't specify any primary keys, Elixir will |
| | 235 | automatically create one called ``id``. |
| | 236 | |
| | 237 | For further information, please refer to the provided examples or |
| | 238 | tutorial. |
| | 239 | ''' |
| | 240 | |
| | 241 | class __metaclass__(type): |
| | 242 | def __init__(cls, name, bases, dict_): |
| | 243 | # only process subclasses of Entity, not Entity itself |
| | 244 | if bases[0] is object: |
| | 245 | return |
| | 246 | |
| | 247 | # create the entity descriptor |
| | 248 | desc = cls._descriptor = EntityDescriptor(cls) |
| | 249 | EntityDescriptor.current = desc |
| | 250 | |
| | 251 | # process statements |
| | 252 | Statement.process(cls) |
| | 253 | |
| | 254 | # setup misc options here (like tablename etc.) |
| | 255 | desc.setup_options() |
| | 256 | |
| | 257 | # create table & assign (empty) mapper |
| | 258 | desc.setup() |
| | 259 | |