Knowing whether an object has at least one reverse related object

Author Message

alessio asistar

Friday 13 May 2011 6:32:06 am

Hi!
I need to know whether an object has reverse related objects
I found this code:
{def $objects=fetch( 'content', 'reverse_related_objects',
hash( 'object_id', $node_id ) )
$counter = 0}

{foreach $objects as $object}
{set $counter=$counter+1}
{/foreach}
this here:
http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/reverse_related_objects
In this way I "count" the number of reverse related objects, but I'm sure there is another way, because I just want to know if the object has reverse objects related or not, I think it's a waste of resources.

Thanks

Alessio

André R.

Friday 13 May 2011 6:49:02 am

You can use http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/reverse_related_objects_count

Or related_contentobject_count / reverse_related_contentobject_count on content object: http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Objects/ezcontentobject

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

alessio asistar

Friday 13 May 2011 8:13:56 am

I have found:

{$node.object.reverse_related_contentobject_count}

but does not work.

Alessio

Luc Chase

Thursday 19 May 2011 12:28:07 pm

{fetch( 'content', 'reverse_related_objects_count', 
hash( 'object_id', $node.contentobject_id,
'all_relations', true() 
))}

The above works for all types of reverse relations ( not just object level, but also attribute-level ). If 'all_relations' is omitted from the fetch statement, it would default to false and the fetch would then not show attribute-level relations.

Your relations, in this case, are at attribute level.  {$node.object.reverse_related_contentobject_count}   works for object-level relations but apparently not for attribute-level.  And it is deprecated anyway.

The Web Application Service Provider

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 18 2025 02:52:33
Script start
Timing: Jan 18 2025 02:52:33
Module start 'layout'
Timing: Jan 18 2025 02:52:33
Module start 'content'
Timing: Jan 18 2025 02:52:34
Module end 'content'
Timing: Jan 18 2025 02:52:34
Script end

Main resources:

Total runtime0.8092 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 588.1719152.6563
Module start 'layout' 0.00590.0028 740.828139.5313
Module start 'content' 0.00870.7994 780.3594583.1250
Module end 'content' 0.80800.0011 1,363.484412.0938
Script end 0.8092  1,375.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4055160.0002
Check MTime0.00140.1709160.0001
Mysql Total
Database connection0.00110.136410.0011
Mysqli_queries0.757993.6648620.0122
Looping result0.00060.0729600.0000
Template Total0.778996.320.3895
Template load0.00210.261820.0011
Template processing0.776895.999720.3884
Template load and register function0.00020.021710.0002
states
state_id_array0.00100.124610.0010
state_identifier_array0.00060.073720.0003
Override
Cache load0.00180.2215290.0001
Sytem overhead
Fetch class attribute can translate value0.00050.059630.0002
Fetch class attribute name0.00170.216150.0003
XML
Image XML parsing0.00080.104830.0003
class_abstraction
Instantiating content class attribute0.00000.001950.0000
General
dbfile0.00170.2050170.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs