Martijn Faassen wrote:
David Pratt wrote: [snip]
For me, the crux of the rdb approach for legacy code is the container, location and traversal. You have been very generous with your examples. I am really hoping for a clearer idea of handling Container, OrderedContainer, and Location which is prevalent in legacy code. Overall, I can say that I quite the innovation here in getting to a 'leaner' concept of Zope.
I myself wouldn't be inclined to call Container and Location only relevant to legacy code.
It's very convenient to have a RDB-backed object have a location, as that allows you to get the URL for it in the regular manner.
Right. ILocation makes sense everywhere you want to place any sort of objects (whether ZODB or not) in a hierarchy. Such hierarchy can then be used by URL generation, security policies (for acquiring security settings), etc. Also, containers make a lot of sense since they essentially are like tables or table views.
For Container, in the megrok.rdb prototype code we actually make containers be SQLAlchemy 'MappedCollection' objects. MappedCollection happens to implement the container API already.
Note that naively speaking, the IContainer and dict APIs are the same. But technically, they're not entirely. dict keys can be anything hashable. IContainer keys must be unicode or str objects.
This way we can make relations be containers by writing something like:
class Departments(rdb.Container): # this is a MappedCollection rdb.key('title')
I think here it would be great if the grokker for rdb.Container could somehow find out whether 'title' was a text column. If it's not, it's not a valid container key, unless perhaps rdb.Container contained some conversion magic.
class Faculty(rdb.Model): # rdb.table_name('faculty') is the default __tablename__ = 'faculty'
grok.traversable('departments')
departments = relation('Department', backref='faculty', collection_class=Departments)
The 'departments' attribute is a container you can traverse into this way. You can hook up views to Departments just like you would to any container.
Yep. Very nice :)