Forums / General / Reverse related objects and sorting by attribute

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.

eZ debug

Timing: Jan 18 2025 11:28:12
Script start
Timing: Jan 18 2025 11:28:12
Module start 'content'
Timing: Jan 18 2025 11:28:13
Module end 'content'
Timing: Jan 18 2025 11:28:13
Script end

Main resources:

Total runtime0.9933 sec
Peak memory usage4,096.0000 KB
Database Queries189

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.9688180.8203
Module start 'content' 0.00770.8271 769.7891453.5781
Module end 'content' 0.83490.1584 1,223.3672338.1016
Script end 0.9932  1,561.4688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.4224210.0002
Check MTime0.00150.1530210.0001
Mysql Total
Database connection0.00140.135910.0014
Mysqli_queries0.922892.89921890.0049
Looping result0.00230.23451870.0000
Template Total0.960896.720.4804
Template load0.00200.198120.0010
Template processing0.958896.531120.4794
Template load and register function0.00030.027710.0003
states
state_id_array0.00180.183110.0018
state_identifier_array0.00170.166220.0008
Override
Cache load0.00160.1633190.0001
Sytem overhead
Fetch class attribute can translate value0.00160.158420.0008
Fetch class attribute name0.00120.123120.0006
XML
Image XML parsing0.00060.058120.0003
class_abstraction
Instantiating content class attribute0.00000.000620.0000
General
dbfile0.00170.1757210.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs