eZ Publish Dev Tip #2 – Nodes and objects
A lot of developers starting out with eZ Publish have a hard time and this is generally attributed to a steep learning curve. Whilst this is true, a lot of the initial issues are terminology related, unless you know what it is called, you can’t search for it – and in technical documentation like that of eZ Publish, if you can’t name it then you won’t find it.
One common issue is trying to work out the difference between a node and an object. Everyone knows that screen – in the details pane on the admin interface, where you see “Node ID” and “Object ID”. But what do they mean and why do they get used?
Objects
Every piece of content in eZ Publish is an object. Many of these are defined by your content classes, but suffice to say that objects actually contain content and by themselves are the single place in which 99% of your content actually resides.
Objects themselves have no hierarchy, you could imagine these are blobs of data just floating around in your database. In order to actually give our site structure, hierarchy, navigation we need to associate these objects (pieces of content) to a node.
Nodes
Nodes exist for one reason, to provide hierarchy to those objects that we just covered. In giving an object a node id, we in turn place it within the node hierarchy, it has a parent, could have children and from this we can base our navigation and other structures.
Objects have a one to many mapping with nodes, meaning that a single piece of content can be referenced by more than one node id. A single node cannot reference multiple pieces of content. The benefit this provides is locations or cross-pubishing in eZ Publish talk, allowing you to have the same piece of content multiple times within your structure, and editing any of those locations edits that single piece of content, the effect of course being that those edits are shown in all locations at once.
Summary
Object IDs are used when referencing a piece of content directly.
Node IDs are used when referencing a specific location in the node tree/hirerarchy of your website.
You will find these terms used througout the documentation and depending on the operations and functions you are calling will determine whether you need to provide a node id or object id for your operation.