What are the differences between getRawSomething
and getSomething
methods on Archetypes contents (eg. ATNewsItem)?
For exemple, what is the difference between getRawImage
and getImage
? Or getRawRelatedItems
and getRelatedItems
? etc.
getRaw*
gives you the direct, unprocessed raw data as stored on the object. The get*
methods are allowed to transform that data in some way as needed.
For example, TextField
fields will transform text to safe HTML when using get
, but getRaw()
gives you the untransformed data, be that markdown, restructuredtext or unprocessed HTML.
From the developer documentation:
Archetypes has two kinds of access methods:
- normal,
getSomething()
, which filters output;- raw, the so-called edit accessor,
getRawSomething()
which does not filter output.
When you want to edit the current contents of a field, use getRaw*
, when rendering the contents, use get*
.
Specifically, related items are stored in a reference field, where the getRaw()
method returns object UIDs, the get()
method returns objects, having first resolved the UIDs for you.
Image fields, like file fields, will wrap the data in the associated object type (OFS.Image
for image fields) if not already that type when using .get()
but return whatever the underlying storage has got for .getRaw()
. Usually the object is already wrapped though.