how can i use the reverse_related_objects fetch function?

Author Message

Seb gaillard

Tuesday 03 March 2009 5:24:01 am

Hi,

I want to use the reverse_related_objects fetch function.
I'm using eZ publish 4.0.1.
The doc says:

fetch( 'content', 'reverse_related_objects',
       hash( 'object_id',            object_id,
           [ 'attribute_identifier', attribute_identifier, ]
           [ 'all_relations',        boolean,              ]
           [ 'group_by_attribute',   boolean,              ]
           [ 'sort_by',              sort_by               ]
           [ 'ignore_visibility',    ignore_visibility     ] ) )

I have 2 classes: Author (A) and Book (B).
The B as an attribute called 'author' where the datatype is 'Object relations'.

When i want to see an author (A), i want to display all his books.

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 'object_id', $node.contentobject_id) 
) }

First of all, i don't understand why I have an empty arry if i don't put this line on the hash 'all_relations', true()

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 
   'object_id', $node.contentobject_id,
   'all_relations', true()
) 
) }

now, i have all the reverse related objects of the current object. I want to have only the books.

When i do this:

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 
   'object_id', $node.contentobject_id,
   'all_relations', true(),
   'attribute_identifier', 'book/author'
) 
) }

it doesn't work...

Any ideas ,

Thanks

Jean-Yves Zinsou

Tuesday 03 March 2009 7:33:09 am

hi there,
indeed you have to use the parameter all_relations to fetch related objects that are made through an attribute of type obejct relation or object relations.

Try to set your attribute identifier by its id as integer and not as string

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 

  'object_id', $node.contentobject_id,
  'all_relations', true(),
  'attribute_identifier', 134
) 
) }
 

for example

Do Androids Dream of Electric Sheep?
I dream of eZpubliSheep....
------------------------------------------------------------------------
http://www.alma.fr

Seb gaillard

Tuesday 03 March 2009 7:51:01 am

Thanks jean-Yves,

I have already tried. It doesn't work...
for example, the attribute author (id: 268) of the class book

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 
  'object_id', $node.contentobject_id,
  'all_relations', true(),
  'attribute_identifier', 268
) 
) }

 

Jean-Yves Zinsou

Tuesday 03 March 2009 8:00:36 am

Ok,

It may sound stupid but i have come across really curious things in ez...
the following code is one that works in one of my apps

{def $related=fetch( 'content', 'reverse_related_objects',
hash( 'object_id', $pays.contentobject_id ,
'attribute_identifier','user/managed_countries',
'all_relations',true()))}

The only difference is the all_relations at the end of the statement...Give it a try !
Does not cost a thing ...
hth

Do Androids Dream of Electric Sheep?
I dream of eZpubliSheep....
------------------------------------------------------------------------
http://www.alma.fr

Seb gaillard

Tuesday 03 March 2009 8:54:55 am

Argh,

I've tried this... and it doesn't work!

{def $livres = fetch( 'content', 'reverse_related_objects',
	hash( 'object_id', $node.contentobject_id,
		'attribute_identifier', 570,
		'all_relations', true()
               )
   )
}

Are you using eZ 4.0.1 ???

Jean-Yves Zinsou

Tuesday 03 March 2009 9:04:03 am

bonjour ;-)

haven't you say that the attribute identifier of the author attribute in book class was 268 ?

Do Androids Dream of Electric Sheep?
I dream of eZpubliSheep....
------------------------------------------------------------------------
http://www.alma.fr

Seb gaillard

Tuesday 03 March 2009 9:13:16 am

Re,

I used 268 for example.
I don't make mistake (ok, i don't speak a good english...) about the id.

Jean-Yves Zinsou

Tuesday 03 March 2009 9:27:15 am

Well,
sorry not to be of any help,
My apps started in ez 4.0.1 an has been migrated in 4.0.2...
And it works...

If it does not on your app, and if there are no errors in the error.log, i really don't know what to say...

Please tell me when you find out what was wrong ...

Do Androids Dream of Electric Sheep?
I dream of eZpubliSheep....
------------------------------------------------------------------------
http://www.alma.fr

Patrick Renaud

Wednesday 04 March 2009 1:11:41 am

Hi Seb,
Have you tried using only hard-coded values ? Without the "all_relations" parameter, useless when you specify the attribute ?

{def $OR = fetch( 'content', 'reverse_related_objects', 
hash( 
  'object_id', 1234,
  'attribute_identifier', 268
) 
) }

Ca, c'est fait !

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 19:22:59
Script start
Timing: Jan 18 2025 19:22:59
Module start 'layout'
Timing: Jan 18 2025 19:22:59
Module start 'content'
Timing: Jan 18 2025 19:23:00
Module end 'content'
Timing: Jan 18 2025 19:23:00
Script end

Main resources:

Total runtime0.7385 sec
Peak memory usage4,096.0000 KB
Database Queries77

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 588.1719152.6563
Module start 'layout' 0.00710.0039 740.828139.5078
Module start 'content' 0.01100.7262 780.3359662.7813
Module end 'content' 0.73720.0013 1,443.117220.0938
Script end 0.7385  1,463.2109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4207160.0002
Check MTime0.00130.1715160.0001
Mysql Total
Database connection0.00090.127810.0009
Mysqli_queries0.659589.2953770.0086
Looping result0.00070.0969750.0000
Template Total0.708595.920.3543
Template load0.00190.263920.0010
Template processing0.706595.667120.3533
Template load and register function0.00030.035110.0003
states
state_id_array0.00090.127810.0009
state_identifier_array0.00080.109520.0004
Override
Cache load0.00170.2294710.0000
Sytem overhead
Fetch class attribute can translate value0.00070.097630.0002
Fetch class attribute name0.00130.1809110.0001
XML
Image XML parsing0.00130.173030.0004
class_abstraction
Instantiating content class attribute0.00000.0044140.0000
General
dbfile0.00100.1301210.0000
String conversion0.00000.001340.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
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
22content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
10content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 56
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs