[storm] Storm, sqlite, and lists

shawn bright nephish at gmail.com
Fri Jul 27 18:16:13 BST 2007


Yes, this answers my question exactly.

thanks much

shawn

On 7/27/07, Jamu Kakar <jamshed.kakar at canonical.com> wrote:
>
> Hi Shawn,
>
> Note: Please include storm at lists.canonical.com in your responses.
>
> shawn bright wrote:
> > if i have a new object, and i need to know its id, because it is related
> > to another object, how do i get that id ? I would need to commit(), then
> > re-select it ?
>
> Nope, you don't need to commit for this case.  For the most part, you
> can just access the attribute and Storm will auto-flush the changes to
> the database (without actually committing the changes).  For example,
> the following should work:
>
> class Person(Storm):
>
>     __storm_table__ = "person"
>
>     id = Int(primary_key=True)
>     name = Unicode(allow_none=False)
>
>     def __init__(self, name):
>         self.name = name
>
> class Account(Storm):
>
>     __storm_table__ = "account"
>
>     id = Int(primary_key=True)
>     owner_id = Int()
>
>     owner = Reference(owner_id, Person.id)
>
> # We'll create an Account object and add it to a store.
> account = store.add(Account())
>
> # Storm's auto-flushing capability with get an ID, if need be.
> print account.id
>
> # The new person object will be automatically added to the store, by
> # way of association with the Account.
> account.owner = Person("Bob")
>
> # Again, Storm's auto-flushing will get an ID, if necessary.
> print account.owner.id
>
> Does this answer your question?
>
> Thanks,
> J.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20070727/94897621/attachment.htm 


More information about the storm mailing list