Forums / General / Reverse related objects and sorting by attribute

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

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.