[storm] Validation of referenced objects

Michael Löffler ml at mldesign.net
Thu Aug 18 11:25:07 UTC 2011


Hi list!

I'm looking for an elegant way, to validate referenced objects. Let's 
say, I have a table 'persons' with the attributes 'father', 'mother', 
'age', and I want to validate for example, that the parents are actually 
older then their children. So I have code like

class Person(object):
     __storm_table__ = 'persons'
     id = Int(primary=True)
     father_id = Int()
     father = Reference(id, father_id)
     ...

Adding a validator to the father_id attribute would have to look up the 
object by the id first, and then process the validation, even if the 
reference already knows the referenced object. This extra lookup would 
be inefficient in my eyes. On the other side, a Reference doesn't seem 
to have a validation mechanism. Would it be wise, to somehow subclass 
Reference, or do I better stick with the lookup of the id? Are there any 
side effects I should be aware of?

Regards,

Michael



More information about the storm mailing list