Iterating relation_list

Author Message

Felix Laate

Thursday 06 September 2007 5:25:57 am

Hi all,

I have a node of a class which has an attribute of type Object Relations. Now I want to make a <i>foreach</i>-loop iterating through those relations.

I tried this (simplified):

{foreach $node.data_map.images...relation_list as $image}
   {$image.name}
{/foreach}

but I get zippo (which would be nice if I were a serialsmoker).

I should know how to do this, but my head is working at half the speed of a C64, so I just can't remember.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Łukasz Serwatka

Thursday 06 September 2007 10:29:06 am

Hi Felix,

You need to access it via .content.relation_list of this attribute then make object fetch based on given object_id from relation_list Then you should see results.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

André R.

Thursday 06 September 2007 3:09:57 pm

Also remember to see if the node_id is set on the object you fetch, that way you can filter out objects that are placed in the trash..

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

Felix Laate

Thursday 06 September 2007 3:56:21 pm

Thank you guys!

Will test this soonish .-)

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Bruce Morrison

Thursday 06 September 2007 5:29:12 pm

Here is a code snippit for those playing at home...

{foreach $node_content.data_map.rl_attribute.content.relation_list as $details}
   {def $rlt_node=fetch('content','node',hash('node_id',$details.node_id))}
   {if $rl_node}{node_view_gui view=line content_node=$rl_node}{/if}
   {undef $rl_node}
{/foreach}
my head is working at half the speed of a C64

You mean a VIC20 ;) ...ahh memories

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Xavier Dutoit

Friday 07 September 2007 10:13:02 am

Little warning: this becomes quite quite slow as soon as you have a lot of related objects. I'm not talking about felix brain, I'm talking about zillions of fetch/compile...

X+

http://www.sydesy.com

André R.

Friday 07 September 2007 10:58:34 am

That’s quite easy to fix, write a small template operator that takes care of the fetching by fetching all objects at once.

In the api you can fetch several nodes at once using:

eZContentObjectTreeNode:fetch

Or several objects at once using:

eZContentObject::fetchIDArray

The first one will skip trashed objects, and the last one will have main_node_id set to NULL if I remember correctly.

If you for some reason have waste amounts of relations, you should also let the operator handle paging.

{def $objects = multi_object_fetch( $node.data_map.rl_attribute.content.relation_list[, $offset = 0[, $limit = 10 ] ]  )}

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

Felix Laate

Friday 07 September 2007 12:34:46 pm

The Bruce-doctrine worked like a charm. But André's suggestion seems to be funnier, so I will try that approach as well.

By the way, the thing I'm working on is a gallery-template based on mootools.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

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:09:50
Script start
Timing: Jan 18 2025 19:09:50
Module start 'layout'
Timing: Jan 18 2025 19:09:50
Module start 'content'
Timing: Jan 18 2025 19:09:50
Module end 'content'
Timing: Jan 18 2025 19:09:50
Script end

Main resources:

Total runtime0.0205 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 587.9063152.6250
Module start 'layout' 0.00660.0043 740.531339.4453
Module start 'content' 0.01090.0072 779.9766101.4297
Module end 'content' 0.01810.0022 881.406342.3047
Script end 0.0203  923.7109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002813.6850140.0002
Check MTime0.00125.7606140.0001
Mysql Total
Database connection0.00094.534910.0009
Mysqli_queries0.003416.575830.0011
Looping result0.00000.097910.0000
Template Total0.00178.310.0017
Template load0.00094.623410.0009
Template processing0.00083.694810.0008
Override
Cache load0.00063.176310.0006
General
dbfile0.00178.522180.0002
String conversion0.00000.058340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs