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
Relation typeone_to_one, many_to_one, one_to_many, many_to_many
PickerA dropdown, or a modal window for choosing
ModelWhat is being linked to
Display fieldWhat the editor sees in the list
Value fieldWhat gets saved, id by default
Sort by, Direction, LimitShape the list offered
ConditionA 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