Skip to content

Relationship Field (PRO) ​

A link from this record to records of another model — a product to its brand, an article to its authors.

Settings:

SettingWhat it does
Relationship typeone_to_one, many_to_one, one_to_many, many_to_many
PickerA dropdown, or a modal window for choosing — the modal only applies to the *_to_one kinds
ModelWhat is being linked to
DisplayWhat the editor sees in the list, name by default
ValueWhat gets saved, id by default
Sort field, Sorting direction, Page sizeShape the list offered
Condition (where)A filter, as JSON, so the list offers only what fits

The type decides the shape of the value: the two *_to_one kinds save a single identifier, the two *_to_many kinds save a list of them and let the editor pick several.

Output:

html
{foreach $authors as $id}
    …
{/foreach}

The field saves identifiers, not records

What lands in the value is ids — that is all. There is no ready-made snippet that turns them back into rows, so fetch them yourself, by the ids you stored:

html
{pbList(model = 'Author', where = '{"id:IN": ' ~ $authors ~ '}', tpl = 'author')}

Plan for that when you choose this field: it links records, it does not join them.

© PageBlocks 2019-present