[storm] Implementing auto add parent
James Henstridge
james at jamesh.id.au
Fri Feb 12 08:03:42 GMT 2010
On Fri, Feb 12, 2010 at 3:19 AM, Eduardo Willians <edujurista at gmail.com> wrote:
>> So, the underlying problem here is that Storm doesn't know that the
>> Session record you've created depends on the Oper record. The
>> "self.id = oper.id" statement just looks like an assignment.
>>
>> You might be able to fix this by using the reference to set self.id:
>> self.oper = oper
>>
>> The reference code will make sure that oper is then flushed first
>
>> In general, the answer is to use references. If you're in a situation
>> where that isn't possible, then explicitly using the
>> store.add_flush_order() method might help (although that needs a
>> store).
>
> SOLVED.
>
> Just using "ReferenceSet( )":
>
> <code>
>
> class Session(object):
> __storm_table__ = "financial.session"
> id = RawStr(primary=True)
> initial = Float()
> # Refs
> oper = Reference(id, Oper.id)
>
> def __init__(self, root, operator, initial, date_time=None,
> add_oper=True):
> oper = Oper(root, operator, date_time, add_oper)
> self.id = oper.id
> self.initial = initial
> self._oper_ref = ReferenceSet(self.__class__.id, Oper.id) #
> Here is the answer
>
> </code>
That isn't what I suggested, and it doesn't look like correct Storm
usage (ReferenceSets should be created at the class scope rather than
once per instance). Didn't changing "self.id = oper.id" to "self.oper
= oper" work?
James.
More information about the storm
mailing list