Href, Multihref and Object Data Fields
Href, multihref and objects are pure relation data types, which means they represent a relation to an other pimcore element (document, asset, object). The href and multihref data types can store relations to any other pimcore element. In the object field definition there is the possibility to configure which types and subtypes of elements are allowed. The configuration screen for restrictions is shown below. The difference between href and multihref is, that a href represents a :1 relation, whereas a a multihref can be a :n relation. The objects field allows relations to one or more objects, but no other elements, therefore the restriction settings for objects are limited to object classes.

Multihref and objects are grid widgets in the UI. The width and height of the input widget can be configured in the object class settings. For a href only the width can be configured, since it is represented by a single drop area. Lazy Loading is explained further below in the section about relations and lazy loading.

The input widgets for all three relation data types are represented by drop areas, which allow to drag and drop elements from the tree on the left to the drop target in the object layout. The href constitutes a single drop area, whereas multihref and objects are grid widgets containing rows of data. In addition to the drag and drop feature, elements can be searched and selected directly from the input widget. In case of objects it is even possible to create a new object and select it for the objects widget. 
These pure relation types are stored in a separate database table called object_relations_ID. In the according object_~ID~ database view, which is used for querying data, the relations fields are summarized as a comma separated list of IDs of related elements. Therefore, if one needs to create an object list with a filter condition on a relation column this can be achieved as follows:
$relationId = 345; $list = new Object_Example_List(); $list->setCondition("myMultihref like '%,".$relationId.",%'"); $objects=$list->load();
In order to set a href data field, a single pimcore element needs to be passed to the setter. With multihref and objects an array of elements is passed to the setter:
$myHrefElement = Document::getById(23); $myMultihrefElements[] = Asset::getById(350): $myMultihrefElements[] = Object::getByPath("/products/testproduct"); $myObjectsElements[] = Object_Product::getById(98); $myObjectsElements[] = Object_Product::getById(99); $object->setHref($myHrefElement); $object->setMultihref($myMultihrefElements); $object->setObjects($myObjectsElements); $object->save();
Dependencies and Lazy Loading

Lazy Loading is a feature introduced with pimcore version 1.3.0
| Lazy Loading is a feature introduced with pimcore version 1.3.0 |
There are several object data types which represent a relation to an other pimcore element. The pure relation types are
- Href
- MultiHref
- Objects
Furthermore, the following data types represent a relation, but they are not reflected in the object_relation_.. tables, since they are by some means special and not pure relations. (One could argue that the image is, but for now it is not classfied as a pure relation type)
- Image
- Link
- Wysiwyg
All of these relations produce a dependency. In other words, the dependent element is shown in both element's dependencies tab and pimcore issues a warning when deleting an element which has dependencies. 
Whenever an object is loaded from database or cache, all these related objects are loaded with it. Especially with MultiHrefs and Objects it is easy to produce a huge amount of relations, which makes the object or an object list slow in loading. As as solution to this dilemma, multihref and object data types can be classfied as lazy loading attributes in the class definition.
Object attributes which are lazy, are only loaded from the database/cache when their getter is called. In the example above this would mean, that the multihref data is only loaded when calling
$object->getMultihref();
otherwise the attibute ($object->multihref) remains null.
In order to remove all elements from this object's multihref field, the setter can be called with null or an array:
$object->setMultihref(array()); //that would have the same result $object->setMultihref(null);
Internally the setter sets the value to an empty array, regardless if an empty array or null is passed to it.
| Be Careful - Use Getters and Setters! $object->multihref = null; Will not work to clear the list of elements in the multihref when lazy loading ist activated. If the value of an object or multihref data type is null, for pimcore this means that the data of this field has not been loaded an that it is not to be touched when saving the object. |
Objects with Metadata (since 1.4.2)
This data type is an extension to the objects data type. To each assigned object additional metadata can be saved. The type of the metadata can be text, number, selection or a boolean value.
A restriction of this data type is that only one allowed class is possible. As a result of this restriction, it is possible to show data fields of the assigned objects.
Which metadata columns are available and which fields of the assigned objects are shown has to be defined during the class definition.

The shown class definition results in the following object list in the object editor. The first two columns contain id and name of the assigned object. The other four columns are metadata columns and can be edited within this list.

All the other functionality is the same as with the normal objects data type.
To access the metadata programmatically have a look at following code snipped.
$object = Object_Abstract::getById(73585); //getting list of assigned objects with metadata (array of Object_Data_ObjectMetadata) $objects = $object->getMetadata(); //get first object of list $relation = $objects[0]; //get relation object $relationObject = $relation->getObject(); //access meta data via getters (getter = key of metadata column) $metaText = $relation->getText(); $metaNumber = $relation->getNumber(); $metaSelect = $relation->getSelect(); $metaBool = $relation->getBool(); //setting data via setter $relation->setText("MetaText2"); $relation->setNumber(5512); $object->save();
Comments (1)
Jan 12, 2011
Jeroen van Sluijs says:
It really took me some time to figure out how I could actually add data to an ob...It really took me some time to figure out how I could actually add data to an object-relation. Key is: just edit an object and drag other objects (from tree on the left) into the table-area.
This might be helpful for other newbies :)