Forums / Setup & design / Reverse relation - I'm doing my best, but it isn't working

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

eZ debug

Timing: Jan 30 2025 21:25:00
Script start
Timing: Jan 30 2025 21:25:00
Module start 'content'
Timing: Jan 30 2025 21:25:00
Module end 'content'
Timing: Jan 30 2025 21:25:00
Script end

Main resources:

Total runtime0.3326 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 588.1719370.2734
Module start 'content' 0.00680.0145 958.44531,013.7500
Module end 'content' 0.02130.3113 1,972.19533,902.3672
Script end 0.3326  5,874.5625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00471.4206200.0002
Check MTime0.00140.4183200.0001
Mysql Total
Database connection0.00070.220910.0007
Mysqli_queries0.230169.18391410.0016
Looping result0.00160.48991390.0000
Template Total0.310893.510.3108
Template load0.00080.233610.0008
Template processing0.310193.214610.3101
Override
Cache load0.00050.162310.0005
Sytem overhead
Fetch class attribute can translate value0.00230.689610.0023
XML
Image XML parsing0.00030.080310.0003
General
dbfile0.00882.6558200.0004
String conversion0.00000.001930.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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