Forums / Setup & design / Iterating relation_list

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

eZ debug

Timing: Jan 18 2025 16:10:53
Script start
Timing: Jan 18 2025 16:10:53
Module start 'content'
Timing: Jan 18 2025 16:10:54
Module end 'content'
Timing: Jan 18 2025 16:10:54
Script end

Main resources:

Total runtime1.3588 sec
Peak memory usage4,096.0000 KB
Database Queries215

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0043 589.1328180.8438
Module start 'content' 0.00431.1486 769.9766740.1563
Module end 'content' 1.15290.2058 1,510.1328344.4453
Script end 1.3587  1,854.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.2783210.0002
Check MTime0.00130.0950210.0001
Mysql Total
Database connection0.00040.030410.0004
Mysqli_queries1.266993.23542150.0059
Looping result0.00240.17752130.0000
Template Total1.334698.220.6673
Template load0.00220.164020.0011
Template processing1.332398.054820.6662
Template load and register function0.00010.007910.0001
states
state_id_array0.00070.053410.0007
state_identifier_array0.00100.070520.0005
Override
Cache load0.00200.1495500.0000
Sytem overhead
Fetch class attribute can translate value0.00190.137760.0003
Fetch class attribute name0.00140.1025130.0001
XML
Image XML parsing0.00280.209660.0005
class_abstraction
Instantiating content class attribute0.00000.0016160.0000
General
dbfile0.00280.2057540.0001
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
8content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 37
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs