[Cubicweb] straight forward filtering and ordering in the same rql sentence

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Sep 13 16:41:33 CEST 2011


On 13 septembre 09:06, Carlos Balderas wrote:
> Hi List!

Hi Carlos,
 
> I have the following schema:
> 
> Reference done_for Company
> cardinality = '?*'
> 
> This means that a "Company" can have several "References" which is the
> important point for this question.
> What I would like to do is to make a company list ordered by the newest
> modification date of its reference.
> 
> This rql sentence achieves what I am looking for :
>     Any C, MAX(RD) GROUPBY C ORDERBY 2 DESC WHERE R done_for C, R
> modification_date RD
> 
> But I would like to know if you have any other suggestions to build the rql
> sentence?
> 
> I have already tried this one:
>     DISTINCT Any C ORDERBY RD DESC WHERE C is Company, R done_for C, R
> modification_date RD
> but I get this error:
> ** can't sort on variable RD which is linked to a variable in the selection
> but may have different values for a resulting row

This is intented, you can't do this neither using sql (DISTINCT + ORDER on a 
non selected value). If you think about it (or search the internet ;), that 
makes sense.

What doesn't suit you in the first query? Beside using a subquery, I don't
think there is another solution.

-- 
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 mailing list