I'm experimenting a bit with storm, and for the sake of data separation
I created three different tables, all sharing the same unique primary
key.  See the example below.

First of all, why is foo.state None before the add?  Will store.add(foo)
also att foo.state and foo.private? I'm under that impression because of
the tutorial.

Lastly, is this pattern supposed to work? :)  I'm not very familiar with
database design.  Can I have two model classes refering to the same
table?


from storm.locals import *

class FooPrivate(object):
     __storm_table__ = 'foo_private'
     id = Int(primary=True)

class FooState(object):
     __storm_table__ = 'foo_state'
     id = Int(primary=True)

class Foo(object):
     __storm_table__ = 'foo'
     id = Int(primary=True)

     private = Reference(id, FooPrivate.id)
     state = Reference(id, FooState.id)

db = create_database("sqlite:")
store = Store(db)
store.execute("CREATE TABLE foo (id INTEGER PRIMARY KEY)")
store.execute("CREATE TABLE foo_state (id INTEGER PRIMARY KEY)")
store.execute("CREATE TABLE foo_private (id INTEGER PRIMARY KEY)")

foo = Foo()
foo.state = FooState()
foo.private = FooPrivate()

print foo
print foo.state         # None?
print foo.private

store.add(foo)
store.flush()
print foo.id
print foo.state.id
print foo.private.id




-- 
storm mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/storm

Reply via email to