CPE Chapter 5 + Cascading operations question + ORM Shootout
Gustavo Niemeyer
gustavo at niemeyer.net
Mon Jul 16 19:17:23 BST 2007
Hello Eugene,
> I have attached a file named cherry-storm.py which is my take on the
> subject.
That's nice, thanks!
> Does Storm support cascading operations through a cascade=True
> parameter of the Reference or through a special method à la DejaVu
> on_forget or ...?
Not yet.. should be easy to support it, though, since we already have
a clear() method on references that will unlink them.
A few comments:
title = Chars()
(...)
name = Chars()
These should be Unicode.
songs = ReferenceSet("Album.id", Song.album_id)
# Album not aware of itself
(...)
albums = ReferenceSet("Artist.id",Album.artist_id)
# Artist not aware of itself
You don't need string references in this case, as you can use
the just defined attribute, like that:
songs = ReferenceSet(id, Song.album_id)
(...)
albums = ReferenceSet(id, Album.artist_id)
The following isn't totally true:
# must be added to the store before being added to a ReferenceSet field
Storm will happily add referenced objects automatically. What you
have to do is add at least one object of the hierarchy to the store
you want, and Storm will add other objects to the same store. If you
add the "grace" object to the store, in your example, everything else
will be added as well, for instance. You can even add it after the
whole hierarchy has been defined, and everything will still work
fine.
This isn't needed:
store.flush()
Storm will flush data automatically when needed, so that changes take
effect when a query is being done, or when committing.
This:
album = store.find(Album, id=1).one()
may be better written as:
album = store.get(Album, 1)
The second will not touch the database if the object is cached, while the
first has to run the query to give back a result set, and the argument
may be pretty much any expression.
Thanks for providing the example!
--
Gustavo Niemeyer
http://niemeyer.net
More information about the storm
mailing list