[storm] Validation of referenced objects

James Henstridge james at jamesh.id.au
Fri Aug 26 05:50:01 UTC 2011


On Thu, Aug 18, 2011 at 7:25 PM, Michael Löffler <ml at mldesign.net> wrote:
> 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?

If you're talking about something like:

    father = store.get(Person, child.father_id)

Then that won't result in a database query if the father has been
loaded recently in the same transaction. It shouldn't be that
inefficient to use in a validator function.

James.

>
> Regards,
>
> Michael
>
> --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/storm
>



More information about the storm mailing list