views:

255

answers:

1

im reading sqlalchemy and i see the code

employees_table = Table('employees', metadata,
    Column('employee_id', Integer, primary_key=True),
    Column('name', String(50)),
    Column('manager_data', String(50)),
    Column('engineer_info', String(50)),
    Column('type', String(20), nullable=False)
)

employee_mapper = mapper(Employee, employees_table, \
    polymorphic_on=employees_table.c.type, polymorphic_identity='employee')
manager_mapper = mapper(Manager, inherits=employee_mapper, polymorphic_identity='manager')
engineer_mapper = mapper(Engineer, inherits=employee_mapper, polymorphic_identity='engineer')

should i make 'type' an int, with constants in a library? or should i make just make type an enum?

+3  A: 

SQLAlchemy has an Enum type since 0.6: http://www.sqlalchemy.org/docs/reference/sqlalchemy/types.html#sqlalchemy.types.Enum

Or for some older version: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/Enum

Although I would only recommend it's usage if your database has a native enum type. Otherwise I would personally just use an int.

WoLpH