[Cubicweb] ORMHelper registry
sylvain.thenault at logilab.fr
Wed Mar 9 08:52:17 CET 2011
On 08 mars 20:30, Adrien Di Mascio wrote:
> Hi everyone,
> Currently, we use *fetch_attrs* to improve attribute cache control
> and *fetch_order* to control how data should be sorted. This has
> proven to be very useful and easy to use.
> However, in some complex cases, I'd like to be able to give more
> complex hints to the ORM. For instance, I might like to :
> - fetch different attributes according to the relation being
> traversed (not only according to destination type)
> - use RQL functions to change fetch_order
> - sort according to "composed entities" (e.g. if schema defines "A
> rel1 B", "B rel2 (composite) C", I might want A.related('rel1') to
> sort according to C)
> - fetch other relations and other attributes that CubicWeb has no
> chance to guess
> - anything fancy
> I would define and register such helpers in a custom registry, they
> could define selectors, etc. etc. The ORMHelper interface would be
> something like::
> class MyHelper(ORMHelper):
> __select__ = something()
> def fetch_attrs(self):
> return [xxx]
> def fetch_order(self, rql):
> return some_transformed(rql)
> I haven't give a lot of thoughts on the API actually, this is just a
> concept I'd like to be discussed.
> Any thoughts ?
go on my friend ! This remembers me a ticket about moving out the ORM
from Entity, but I can't find it anymore. Begining by an adapter responsible
for control of prefetched attributes and result order sounds cool.
Something like ORMControlAdapter, which should be selectable on entity *class*
(we'll need a new is_class('EType') adapter). We can also discuss why this
has currently to work on class instead of instance and see if it's worth it...
Regarding the API, extracting things we have into an adapter will probably
help to see way to improve it, and context information that can be given.
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
CubicWeb, the semantic web framework: http://www.cubicweb.org
More information about the Cubicweb