[storm] subclassing and foreign keys with respect to properties from parent
Olaf Conradi
olaf at conradi.org
Wed Aug 13 21:43:54 BST 2008
2008/8/13 James Henstridge <james at jamesh.id.au>:
> Storm does not use subclassing to create foreign key relationships.
> What that part of the tutorial is doing is saying "the employee table
> shares the same field definitions as the person table, plus these
> extra ones". There is no person record created when you add a record
> to the employee table.
Ok, so instead of using subclassing I'd be better of using separate classes?
For example, I'm storing credentials for subjects, and each subject
can either be an agent or a person. (I left out the credential part
here)
class Subject(Storm):
__storm_table__ = 'subjects'
id = Int(primary=True)
name = Unicode()
type = Enum(map={'agent': 0, 'person': 1})
type_id = Int()
class Agent(Storm):
__storm_table__ = 'agents'
id = Int(primary=True)
subject_id = Int()
subject = Reference(subject_id, 'Subject.id')
class Person(Storm):
__storm_table__ = 'persons'
id = Int(primary=True)
subject_id = Int()
gender = Enum(map={'Undisclosed': 0, 'Male': 1, 'Female': 2})
date_of_birth = Date()
subject = Reference(subject_id, 'Subject.id')
What would be the best way to add a property to class Subject to get
the real subject depending on the type?
Thanks,
-Olaf
More information about the storm
mailing list