Reverse relation - I'm doing my best, but it isn't working

Author Message

Aleksander Lech

Wednesday 04 January 2006 2:12:11 am

Hi there

I made custom class (A) and put ezobjectrelationlist attribute there.

Then, I created another custom class (B) and populate both with sample data.

Now - object of class A contains object of class B. If I understand it correctly - object of class B is related to object of class A.

I'm trying to display reverse relation - I mean display object of A in object of class B template file using:

{* 189 is $node.contentobject_id *}
{def $objects=fetch( 'content', 'reverse_related_objects',
                     hash( 'object_id', 189 ) )}

{$objects|attribute('show')}
{foreach $objects as $object}
    {$object.name|wash} <br />
{/foreach}

And as you probably guess, it returns nothing.

:(

Aleksander Lech

Wednesday 04 January 2006 2:32:53 am

I found something weird:
This SQL is generated according to reverse_related_objects fetch:

SELECT DISTINCT
    ezcontentobject.*
FROM
    ezcontentobject, ezcontentobject_link
WHERE
    ezcontentobject.id=ezcontentobject_link.from_contentobject_id
AND
    ezcontentobject.status=1
AND
    ezcontentobject_link.to_contentobject_id=285
AND
    ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version
AND
    contentclassattribute_id=0

What is the reason of last two lines? Without it, SQL returns correct data.

Massimiliano Bariola

Wednesday 04 January 2006 2:33:25 am

Hi Alex,

no, a "contains" relationship is not a "relation" relationship. think about the first as folder/file , and the second as "link from A to B".

in admin view, contianed entities are shown indented with respect to their container, as a hiaerarchical tree. Related objects are shown under the detail of the object (lower-center part of the page).

at any rate, try to add a

{$object|attribute(show, X)}

with X = depth of inspection (1 ..... infinite) within your loop and see what exactly object contains.

HTH

Max

Aleksander Lech

Wednesday 04 January 2006 2:47:46 am

Hi Massimiliano,
I did:

{$objects|attribute('show',2)}

But it returns just table header:
Attribute Type Value

And nothing more

Aleksander Lech

Wednesday 04 January 2006 3:29:32 am

Gotcha!

I make it work :) and here's the difference:
Doesn't work:

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

Works:

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

'410' is id of attribute which I wanted to show, but I wonder - if there is a way to display ALL reverse-related objects?

Aleksander

Xavier Dutoit

Thursday 05 January 2006 3:01:31 am

Hi,

Have a look at this discussion that occured when building the fetch method you're using:
http://ez.no/community/forum/general/object_relations

Kristof came up with an extension that solved most of the problems:

http://ez.no/community/contribs/hacks/advanced_content

I don't remember the details, but I'm sure having a look at it will brings you the solution.

Keep us informed about how you've solved your pb.

X+

http://www.sydesy.com

Kristof Coomans

Thursday 05 January 2006 3:18:24 am

You can use the "all_relations" parameter if your eZ publish version is up to date. I don't exactly know when it was added.

For more information, see http://pubsvn.ez.no/nextgen/trunk/doc/features/3.6/related_objects_fetch_functions.txt

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Xavier Dutoit

Thursday 05 January 2006 4:14:03 am

Now that Kristof mention it, he came with the solution with a patch more than an extension.

Resolution for next year: do something to improve my memory ;)

X+

http://www.sydesy.com

Kristof Coomans

Thursday 05 January 2006 7:10:49 am

No, you were right, my temporary solution was an extension ;-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.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 18 2025 11:32:29
Script start
Timing: Jan 18 2025 11:32:29
Module start 'layout'
Timing: Jan 18 2025 11:32:29
Module start 'content'
Timing: Jan 18 2025 11:32:29
Module end 'content'
Timing: Jan 18 2025 11:32:29
Script end

Main resources:

Total runtime0.0196 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.0081 588.1641152.6563
Module start 'layout' 0.00810.0032 740.820339.5078
Module start 'content' 0.01130.0055 780.3281101.5234
Module end 'content' 0.01670.0027 881.851642.3047
Script end 0.0194  924.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003015.5691140.0002
Check MTime0.00126.3004140.0001
Mysql Total
Database connection0.00126.239610.0012
Mysqli_queries0.002311.724330.0008
Looping result0.00000.086410.0000
Template Total0.002311.810.0023
Template load0.00136.883610.0013
Template processing0.00104.896710.0010
Override
Cache load0.00094.477910.0009
General
dbfile0.00031.705780.0000
String conversion0.00000.042640.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