Reverse related objects and sorting by attribute

Author Message

Carlos Revillo

Wednesday 11 June 2008 10:34:02 am

Hi. I have two clases. A class has one attribute as object relation to class b. Btw, i'm using eZ 4.0 for this.

what i want is to know wich A objects are reverse related to some B objects.

So, i'm doing

{def $contents=fetch( 'content', 'reverse_related_objects',
       hash( 'object_id', $b_object.contentobject_id, 
              'attribute_identifier', 371,
       ))}

This works perfeclty. Problems begin when i try to order "$contents" by one attribute from A class. This attribute is a numeric value.

{def $contents=fetch( 'content', 'reverse_related_objects',
       hash( 'object_id', $b_object.contentobject_id, 
              'sort_by', array("attribute", "false()", "a/numeric_field")
       ))}

I'm getting an sql error here. Debut output says

Query error: Column 'contentclassattribute_id' in where clause is ambiguous. Query:
SELECT 
                        ezcontentclass.serialized_name_list AS class_serialized_name_list,
                        ezcontentclass.identifier as contentclass_identifier,
                        ezcontentclass.is_container as is_container,
                        ezcontentobject.* , ezcontentobject_name.name as name,  ezcontentobject_name.real_translation 
                     FROM
                        ezcontentclass,
                        ezcontentobject,
                        ezcontentobject_link
                        , ezcontentobject_name 
                        
                        , ezcontentobject_attribute a0
                     WHERE
                        ezcontentclass.id=ezcontentobject.contentclass_id AND
                        ezcontentclass.version=0 AND
                        ezcontentobject.status=1 AND
                        
                                   a0.contentobject_id = ezcontentobject.id AND
                                   a0.contentclassattribute_id = 341 AND
                                   a0.version = ezcontentobject_name.content_version AND
 ( a0.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 2 ) )
   <
     ( a0.language_id & 1 )
   + ( ( a0.language_id & 2 ) )
 ) 
 AND 
                        ezcontentobject_link.op_code='0'
                         AND contentclassattribute_id=371  AND ( relation_type & 8 ) <> 0 
                         AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND
                                                                      ezcontentobject_link.to_contentobject_id=91887 AND
                                                                      ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version 
                        
                         AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND
                                 ezcontentobject.current_version = ezcontentobject_name.content_version AND 
 ( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) )
   <
     ( ezcontentobject_name.language_id & 1 )
   + ( ( ezcontentobject_name.language_id & 2 ) )
 ) 

                         ORDER BY a0.sort_key_string DESC

for simplify, error is telling about an ambigous field in the query in the where clause. i think this line

 AND 
                        ezcontentobject_link.op_code='0'
                         AND contentclassattribute_id=371  AND ( relation_type & 8 ) <> 0

Is this a bug?

Carlos Revillo

Wednesday 11 June 2008 11:11:53 am

I'm sorry, i forgot this
From the doc.

Please note that this parameter works in the very same way as the "sort_by" parameter of the list fetch function. However, it currently only supports the following sorting methods:
      class_identifier
      class_name
    modified   
      name   
      published  
      section

Maybe sorting by attribute could be added in next releases.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 00:41:10
Script start
Timing: Jan 31 2025 00:41:10
Module start 'layout'
Timing: Jan 31 2025 00:41:10
Module start 'content'
Timing: Jan 31 2025 00:41:10
Module end 'content'
Timing: Jan 31 2025 00:41:10
Script end

Main resources:

Total runtime0.0227 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 588.2578151.2266
Module start 'layout' 0.00500.0039 739.4844220.7188
Module start 'content' 0.00890.0123 960.20311,001.8203
Module end 'content' 0.02120.0014 1,962.023433.9922
Script end 0.0226  1,996.0156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.7779140.0002
Check MTime0.00114.9427140.0001
Mysql Total
Database connection0.00083.545410.0008
Mysqli_queries0.002712.074430.0009
Looping result0.00000.061010.0000
Template Total0.00114.710.0011
Template load0.00083.713610.0008
Template processing0.00021.005210.0002
Override
Cache load0.00062.570710.0006
General
dbfile0.00020.984180.0000
String conversion0.00000.027340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs