eZ Community » Forums » Developer » Reverse relation_list from PHP
expandshrink

Reverse relation_list from PHP

Reverse relation_list from PHP

Tuesday 22 November 2011 5:22:03 pm - 4 replies

Hi there,

I would like to know all the object who are refering an another object using a relation_list.

So I fetched my "included" node :

$o = eZContentObject::fetchByNodeID( $type );

And it is OK.

Now I want to get the list of all the node that include this node with a relation_list.

So I tryed :

$relations = $o->reverseRelatedObjectList();

But the result is empty (and I should have one element).

Am I using the correct method ?

Thanks,

Damien

Tuesday 22 November 2011 6:14:59 pm

That function excludes certain types of object relations by default. You can use this fetch that is documented (which technically calls eZContentObject::reverseRelatedObjectList with some params if you dig deeper):

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/reverse_related_objects

In PHP, something like:

eZFunctionHandler::execute( 'content', 'reverse_related_objects', array(
                                                                                              'object_id' => $o->attribute( 'id' ),
                                                                                              'all_relations' => true
                                                                                              ) );

Modified on Tuesday 22 November 2011 6:22:45 pm by Peter Keung

Wednesday 23 November 2011 10:52:17 am

Thank you very much Peter, it is exactly what I was looking for.

But I am disapointed to discover that it is more easy to use the fetch mecanism from template to access data than to use the standard API.

I hope this will be improved with the futur API.

Cheers.

Thursday 24 November 2011 5:47:23 pm

@Damien - you can hunt down in php code which php function actually implements that fetch:

look in kernel / content / function_defintion.php for $FunctionList['reverse_related_objects'. You find: 'class' => 'eZContentFunctionCollection', 'method' => 'fetchReverseRelatedObjects' ),

this will be in file kernel / content / ezcontentfunctioncollection.php. You can then look up the code of that method to see if you can even use one of its submethods directly.

Tip: install the extensions ezgeshi and ggsysinfo. All of the above hunting will be done for you in a nice GUI in the admin interface

Friday 25 November 2011 11:11:57 am

@Damien - you can hunt down in php code which php function actually implements that fetch:

look in kernel / content / function_defintion.php for $FunctionList['reverse_related_objects'. You find: 'class' => 'eZContentFunctionCollection', 'method' => 'fetchReverseRelatedObjects' ),

this will be in file kernel / content / ezcontentfunctioncollection.php. You can then look up the code of that method to see if you can even use one of its submethods directly.

Tip: install the extensions ezgeshi and ggsysinfo. All of the above hunting will be done for you in a nice GUI in the admin interface

Thanks for this informations Gaetano !

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from