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.