Skip to main content
Version: 4.0 preview

Published

Version
4.0 preview
Updated
View markdown

The publish flag — a boolean specialised for the one field nearly every entity has.

Storage kind: column · Column: varchar(1)

Use it for the field that decides whether a record is live, and only for that: one per model, named published by convention. Any other yes/no is a plain boolean — a second published property on one model gives you two toggles in the list and no way to tell them apart.

Settings

SettingMeaning
defaultUsually 1 — a newly created record is normally live

What it adds over boolean

  • A toggle in the list. The cell renders a check-circle or ban icon carrying trigger-toggle-record-activation and the record id, so a record can be published or unpublished from the list without opening it.
  • A filter, and the conventional CBYES / CBNO labels.

Everything else — the varchar(1) column, the '0'/'1' values, the string-comparison rule for hand-written SQL — is the same as boolean.

Note that the toggle is rendered unconditionally by this type, whereas the filter still needs addDropdownFilter in the definition like any other property.

The column is usually indexed

Published state is in the WHERE clause of most reads, so these columns carry an index. That is worth knowing before changing the type: an indexed column cannot be widened past InnoDB's key limit, which is why 3.6.5 left indexed columns alone and recorded their real width as an explicit dataType instead of migrating them.

Declare 'default' => 1 unless there is a reason new records should start hidden. Whichever you choose, declare it — the same reasoning as for boolean: without a default the column can end up nullable and holding neither value.

@see boolean.md