Author Topic

Kristof Coomans

Wednesday 21 June 2006 11:05:11 am

Comment46236

Hi Fabio

Some example code to add objects to an attribute with the datatype object relation list:

$content = $objectRelationListAttribute->content();
$priority = 1;

foreach ( $objectsToRelate as $objectToRelate )
{
    $content['relation_list'][] = eZObjectRelationListType::appendObject( $objectToRelate->attribute( 'id' ), $priority, $objectRelationListAttribute );
    $objectRelationListAttribute->setContent( $content );
    $objectRelationListAttribute->store();
    $priority++;
}

For an attribute with the object relation datatype, you can use:

$objectRelationAttribute->setAttribute( 'data_int', $objectToRelate->attribute( 'id' ) );
$objectRelationAttribute->store();

Content object relations on attribute level will also be made when you use the code above (the datatypes will take care of it).

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