[Grok-dev] megrok.rdb feedback
faassen at startifact.com
Wed Sep 17 08:14:31 EDT 2008
Lennart Regebro wrote:
> On Tue, Sep 16, 2008 at 13:28, Martijn Faassen <faassen at startifact.com> wrote:
>> I'm not sure I get it. All containers *are* models in Grok. It's just
>> that rdb.Container nor rdb.QueryContainer are not rdb.Model, but more
>> like grok.Model. A model is information mapped from a table. A container
>> is a relationship mapped into an object.
> Well, I couldn't get a container to work unless it also was a model.
What does "work" mean for you? rdb.Container needs to be part of a
SQLAlchemy relation, and it'll work without mixing in rdb.Model or
>> This leaves the starting point however - you need to be able to get to a
>> model before you can get to containers. This is why there is also
>> rdb.QueryContainer, which allows you to create a container that
>> represents a query and is not backed by a relation in the database. This
>> way you can get to your initial models. rdb.QueryContainer is also
>> useful to build query-backed object structures that the ORM doesn't let
>> you create. Both rdb.Container and rdb.QueryContainer make sure that
>> URLs can be generated to the objects inside them.
> OK, this is all very complicated, and not really explained in the
> documentation, and seems to require quite a lot of knowledge before it
> gets really understandable...
It's that *not* complicated. It's a consequence of traversal and object
relational modeling. Once you're off into ORM space, you can traverse
between objects through relations, which are modeled as rdb.Container.
To get *into* ORM space, or if you want to do special things that aren't
so easy to model using the ORM, you can use a QueryContainer.
Have you read the SQLAlchemy ORM tutorial? It doesn't talk about
QueryContainer at all as this is a particular construct megrok.rdb adds,
but much of the rest is explained there.
It's true that using an ORM requires a lot more knowledge than the ZODB
does - the more I do this stuff, the more I appreciate the ZODB. It's
also true that perhaps a routing model like megrok.trails beats
traversal in being easier to understand in this case, though I'm not
quite giving up on traversal yet. :)
More information about the Grok-dev