Fetching objects relating to current object.

Author Message

Gabriel Ambuehl

Wednesday 05 January 2005 8:28:40 am

This must be something trivial I'm overlooking.

I got a Country class (just one field, name of the country) and a Photograph (identifier photograph) class containing various fields among them an object relation to Country (called "Country" and identified by "country").

Now I want the Country template to show photographs taken there:

{section name=Photograph loop=fetch( 'content', 'list',  hash(  attribute_filter,  array('parent_node_id', 93, 'photograph/country', '=', $node.object.id ) ) )  }

<a href={$Photograph:item.main_node.url_alias|ezurl}>{$Photograph:item.name}</a>
{/section}

Edit: maybe this doesn't work at all. ezobjectrelation isn't listed as a attribute_filter enabled data type. So is there any other way to do this?

Visit http://triligon.org

Paul Borgermans

Wednesday 05 January 2005 9:47:08 am

Gabriel,

You will have to use content/search instead of content/list. I do it quite often with the standard related object datatypes (with search restrictions). This strategy does not always work though (all searchable attributes of the related object are used), but it should work in your case. The search string should be simply the $node.name.

We have a custom related object list datatype in use here --made by Hans Melis-- which has the reverse related objects listed, similar to the one posted by Xavier Dutoit. But it is not requiring an extra table. It actually uses the normal object relations to have the reverse list. Maybe Hans should put it in pubsvn too ;-) as it provides this type of functionality

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Gabriel Ambuehl

Wednesday 05 January 2005 10:18:10 am

Actually, it seems to work with:

{section name=Photograph loop=fetch( 'content', 'list',  hash(  attribute_filter,  array('or', array('parent_node_id', 93, 'photograph/country', '=', $node.object.id ) ) ))  }

<a href={$Photograph:item.url_alias|ezurl}>{$Photograph:item.name}</a>
{/section}

I.e. an array('or' [...]) wrapper around the parameters for attribute_filter. I suppose I'll have to use content/tree as it's not entirely clear that all photographs will be direct children of the same node. But I feel I tackled the worst parts.

I will look into content/search though. Thanks for your advice.

Visit http://triligon.org

Gabriel Ambuehl

Thursday 06 January 2005 10:22:22 am

I was looking into content,search but it doesn't ever find anything. Can anyone confirm that it in fact does work on 3.5?

{section loop=fetch( content, search, hash( text, 'Spain') )}
   <a href={$:item.main_node.url_alias|ezurl}>{$:item.name}</a><br />
{/section}

Visit http://triligon.org

Paul Borgermans

Thursday 06 January 2005 10:46:51 am

Hi Gabriel,

The result of the search includes a search count, some other goodies like search words omitted and the searchresults as a sub-array. You should use it like the following:


{let mysearch=fetch( content, search, hash( text, 'Spain') )}
{*discover some more: uncomment the line below*}
{*$mysearch|attribute(show)*}
{*end discover *}
{section loop=$mysearch.SearchResult var=result}
   <a href={$result.main_node.url_alias|ezurl}>{$result.name}</a><br />
{/section}
{/let}

Also notice the better use of <b>var=</b> instead of the swampy section name spaces.

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Gabriel Ambuehl

Friday 07 January 2005 12:30:58 am

Thanks, this works. Seems like the doc to the search operator is totally wrong. I'll file a bug report later on.

Visit http://triligon.org

Jan Borsodi

Friday 07 January 2005 1:31:16 am

The doc for the search operator is now updated.
http://ez.no/ez_publish/documentation/reference/data_fetching/content/search

Is the new text sufficient or should we add more details?

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

Gabriel Ambuehl

Friday 07 January 2005 2:05:57 am

I think the new docs are much better indeed.

Visit http://triligon.org

Xavier Dutoit

Thursday 13 January 2005 1:25:15 pm

Paul mentionned my modest contribution (found on the pubsvn or http://www.ez.no/community/contribs/datatypes/enhanced_objectrelation ) and I think it should do what you need.

Just a small correction on Paul comments: you have to modify one existing table, not add a new one. I wanted to be able to have several attributes relatedobjects on one class I couldn't find a way to know for each related object if it was a plain related object or related because of an objectrelation attribute, and which one.

X+

http://www.sydesy.com

Gabriel Ambuehl

Thursday 13 January 2005 2:05:06 pm

Xavier,
I do in fact like your enhanced object relation very much but it's not really useful as the relations are doubled in 3.5 each edit (look at my postings on the page of the module).

BTW, I have code on my HD to add metadata for searching (only default language so far, though, not sure if it's sensible to also add all translations to the index?). I'd love to share it, please advise where I should put it.

I've also filed a bug related to the cloning: http://ez.no/bugs/view/6081

Visit http://triligon.org

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

Main resources:

Total runtime0.0232 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0119 589.2813152.6406
Module start 'layout' 0.01200.0030 741.921939.4766
Module start 'content' 0.01490.0058 781.3984101.4609
Module end 'content' 0.02070.0025 882.859446.3047
Script end 0.0232  929.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002811.9503140.0002
Check MTime0.00125.2388140.0001
Mysql Total
Database connection0.00093.688010.0009
Mysqli_queries0.008636.960030.0029
Looping result0.00000.051410.0000
Template Total0.00208.510.0020
Template load0.00114.648210.0011
Template processing0.00093.851310.0009
Override
Cache load0.00072.903410.0007
General
dbfile0.00031.379380.0000
String conversion0.00000.029840.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