Accessing an attribute of a class's objectrelation

Accessing an attribute of a class's objectrelation

Thursday 22 January 2004 8:54:00 pm - 17 replies

Author Message

Lazaro Ferreira

Friday 23 January 2004 4:09:59 am

Hi,

Below and example that works for us

{section name=Relation loop=$node.object.data_map.personal_data.content.relation_list}
{let person=fetch(content,object,hash(object_id,$:item.contentobject_id,object_version,$:item.contentobject_version))}
{attribute_view_gui attribute=$:person.data_map.first_name} {attribute_view_gui attribute=$:person.data_map.last_name}
{attribute_view_gui attribute=$:person.data_map.position}
{/let}
{/section}
--------------------
This is a resume class, that links to a person or employee class in a objectrelationlist attribute

Hope this help

Lazaro

Lazaro
http://www.mzbusiness.com

Jason Filby

Friday 23 January 2004 10:19:03 am

Hi Lazaro

Thanks for your reply. That may work for the objectrelationlist, but what about the objectrelation?

Thanks
Jason

Lazaro Ferreira

Friday 23 January 2004 10:31:19 am

Hi Jason,

Try something like this:
----------------------------------------------
{let Relation=$node.object.data_map.personal_data.content.relation} {* personal_data is the name of the relation attribute *}

{let person=fetch(content,object,hash(object_id,$Relation.contentobject_id,object_version,Relation.contentobject_version))} {* Person is the object referenced by relation attribute*}

{attribute_view_gui attribute=$person.data_map.first_name} {attribute_view_gui attribute=$person.data_map.last_name}

{attribute_view_gui attribute=$person.data_map.position}
{/let}

{/let}
--------------------

Lazaro
http://www.mzbusiness.com

Jason Filby

Friday 23 January 2004 10:34:02 am

Hi again

Thanks, but it doesn't work. ezPublish complains that relation does not exist, but try these others: <nothing!>

Cheers
Jason

Lazaro Ferreira

Friday 23 January 2004 10:38:40 am

Hi,

Give me a minute!

Lazaro
http://www.mzbusiness.com

Lazaro Ferreira

Friday 23 January 2004 10:43:28 am

Hi,

should be :
$node.object.data_map.personal_data.content instead of $node.object.data_map.personal_data.content.relation_list

Lazaro
http://www.mzbusiness.com

Jason Filby

Friday 23 January 2004 11:05:32 am

Hi Lazaro

While it now doesn't error, it doesn't get into the loop. Have you tried this code with an objectrelation?

Thanks
Jason

Lazaro Ferreira

Friday 23 January 2004 11:51:08 am

Hi Jason,

The code below, dont use loop, note that I've changed from relation_list (many objects) to relation (only one object):
----------------------------------------------
{let Relation=$node.object.data_map.personal_data.content.relation} {* personal_data is the name of the relation attribute *}

{let person=fetch(content,object,hash(object_id,$Relation.contentobject_id,object_version,Relation.contentobject_version))} {* Person is the object referenced by relation attribute*}

{attribute_view_gui attribute=$person.data_map.first_name} {attribute_view_gui attribute=$person.data_map.last_name}

{attribute_view_gui attribute=$person.data_map.position}
{/let}

{/let}
--------------------

The code above do not loop over attributes instead gets some of them only
If you want to loop over you should change the code to something like this :

{let Relation=$node.object.data_map.personal_data.content.relation} {* personal_data is the name of the relation attribute *}

{let person=fetch(content,object,hash(object_id,$Relation.contentobject_id,object_version,Relation.contentobject_version))} {* Person is the object referenced by relation attribute*}
{* loop over attributes *}
{section name=ContentObjectAttribute loop=$person.contentobject_attributes}
{$ContentObjectAttribute:item.contentclass_attribute.name|wash} {*attribute name*}
{attribute_view_gui attribute=$ContentObjectAttribute:item} {*attribute content*}
{/section}

{/let}
----------------------------------------

Lazaro
http://www.mzbusiness.com

Jason Filby

Friday 23 January 2004 10:46:26 pm

Hi

The .relation isn't accepted by ez. Which version of ezPublish are you using? I'm using 3.3-1.

Cheers
Jason

Jason Filby

Saturday 24 January 2004 12:10:34 am

Hi again

I've upgraded to 3.3-2, still no luck. Has anyone ever got this working? Can it be done??

Thanks
Jason

Lazaro Ferreira

Saturday 24 January 2004 2:38:11 am

Sorry,

Jason I sent you the first code again, it is not 'content.relation', it is just "content"

So it is :
{let Relation=$node.object.data_map.personal_data.content} {* personal_data is the name of the relation attribute *}

----------------------------
Try this, if trouble turn debug on, and tell me what does it show ?
----------------------------------------------------
As I tell you in my first message, I have done, for objectrelation_list
Object relation it is almost the same, the diference is that objectrelation_list returns a collection of objects, and object relation only returns one object

Once, you manage to reference the relation attribute using:
{let Relation=$node.object.data_map.personal_data.content} {* personal_data is the name of the relation attribute Here above I'm assuming that you have accessed your object from the content tree, via $node *}

then you fetch the object referenced by the relation attribbute :
{let person=fetch(content,object,hash(object_id,$Relation.contentobject_id,object_version,Relation.contentobject_version))} {* Person is the object referenced by relation attribute*}

As you said before, you didn't get error till here

then you have two choices, you can loop over the attribures of the relation object attribute, or you can access some especific attributes of it

loop over :
{* loop over attributes *}
{section name=ContentObjectAttribute loop=$person.contentobject_attributes}
{$ContentObjectAttribute:item.contentclass_attribute.name|wash} {*attribute name*}
{attribute_view_gui attribute=$ContentObjectAttribute:item} {*attribute content*}
{/section}

-----------------------------
get some especific attributes, i.e attributes first_name and last_name:

{attribute_view_gui attribute=$person.data_map.first_name}
{attribute_view_gui attribute=$person.data_map.last_name}
------------------------------
So basically this is the code to visualize attributes from an object referenced by an objectrelation attribute
----------------------------
Again We haven't used with relation instead with relation_list, but we clearly understand that from the point on you get the object relation attribute (the first code above) the rest is simply accessing an object, and this is the most common piece of code in every EZP template
-----------------------------
Again run the code and look at debug output, if you didn't get errors from this then the problem isn't it

We have done sucessfully with 3.3-1 and 3.3-2

Lazaro
http://www.mzbusiness.com

Jason Filby

Saturday 24 January 2004 7:14:01 am

Hi

Here's what I've done:

{let Relation=$node.object.data_map.blog_owner.content}
{$Relation.contentobject_id} . {$Relation.contentobject_version}
{let person=fetch(content,object,hash(object_id,$Relation.contentobject_id,object_version,$Relation.version))}
{attribute_view_gui attribute=$person.data_map.person_email}
{/let}
{/let}

The two variables I am displaying between the dot show nothing. So the attribute returns an error because its referencing a NULL object. When I take away the .content from the first line, then the first variable displays a number - but the second doesn't (contentobject_version doesn't exist for that reference). If I change it to version, then they both display numbers - but then it refers back to the original object ($node.object). So it doesn't really work at all. Any other ideas?

Thanks
Jason

Lazaro Ferreira

Saturday 24 January 2004 6:46:25 pm

Hi,

I think the code I sent you before should work

Regarding the problem I only see two possibilities here:

1) There is no object to get back, are you sure that the object referenced by your main object exist (is published, and not in trash), and is linked to your main object ?

2) the expression: $node.object.data_map.your_relation_attribute.content , doesn't work

I don't think the expression (#2) would be the problem

This expression is used by ezpublish itself at ezobjectrelation.tpl
design/standard/templates/content/datatype/view/ezobjectrelation.tpl

Last, you could also try fetching the object without using the version at all

(Actually you only need the object_id to get some object back)

Lazaro
http://www.mzbusiness.com

Jason Filby

Saturday 24 January 2004 10:42:29 pm

Hi Lazaro

Thanks for all the time you've spent on this issue, but I assure you that it does not work. Please if you could try an actual ObjectRelation you would see this.

Thanks
Jason

Jason Filby

Monday 26 January 2004 10:21:33 am

Hi

Can someone please help with with this issue.

Thanks
Jason

Lazaro Ferreira

Friday 06 February 2004 2:47:58 am

Hi,

You better post this issue at bug report, EZP has a person fully dedicated to check all of the bug reports, so chances are that you will get feedback from them

 

Lazaro
http://www.mzbusiness.com

John Dalton

Tuesday 13 April 2004 7:37:42 pm

Hi Jason,

I've struggled with this too. I eventually found an attribute which works pretty much by trial and error, using the attribute(show) command to view them all.

The object id of the related object is stored in the data_int attribute of the object relation field. This seems pretty counter-intuitive to me.

Assuming you're viewing the node associated with your 'container' object, and the object contains a field called related_object, you can use code like the following:

  {let relobject=fetch( 'content', 'object',
                        hash( 'object_id', $node.object.data_map.related_object.data_int )
                       )
  }

  {$relobject.name}

This can be used (modified) inside a loop or whereever you like - once you know that you can find the required value inside data_int, the rest is easy.

I hope this helps,

John Dalton

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.