Forums / Developer / Knowing whether an object has at least one reverse related object

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