[storm] Implementing auto add parent

Eduardo Willians edujurista at gmail.com
Fri Feb 12 11:20:03 GMT 2010


> 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?

Once SOLVED now.

LOL :)

Sorry for misunderstanding. I tried that, but I've got an "WrongStoreError":

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    financial.add(ses)
  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 249, in add
    raise WrongStoreError("%s is part of another store" % repr(obj))
WrongStoreError: <share.models.financial.tables.Session object at
0xa59024c> is part of another store

So now I tried to use "ReferenceSet" (instead of "Reference") in class
scope and then added "self.oper = oper" and it worked. Here is the
code:

<code>

class Session(object):
    __storm_table__ = "financial.session"
    id = RawStr(primary=True)
    initial = Float()
    # Refs
    oper = ReferenceSet(id, Oper.id)

    def __init__(self, root, operator, initial, date_time=None,
                 add_oper=True):
        self.oper = Oper(root, operator, date_time, add_oper)
        self.id = self.oper.id
        self.initial = initial

</code>

Register that if I dont use "self.id = self.oper.id" I get and
"IntegrityError" for using NULL value for id column.

So, thank you again.

Eduardo Willians



More information about the storm mailing list