MishkaDocument. Resources. Validations. SameWorkspaceVersion
(Mishka Document v0.0.1)
Copy Markdown
View Source
Refuses a record that names, by id, a record of the wrong workspace version.
A section, a section draft and a note draft live in one workspace version (workspace_version_id)
and name the records around them by id: a parent section, the section a draft changes, the note a
draft rewrites. Those are the same version's records, or the version's tree and the drafts applied
to it put a record where nobody reading that version finds it. A section's source is the section it
was copied from, which is in another version of the same workspace.
Checked when the id or the record's own version changes, whoever writes. Nothing is checked when either is absent. A record named that cannot be read is refused.
Each refusal is written in the Gettext locale of the process the action runs in, errors domain
of MishkaCmsCore.Gettext, with the :label translated in the same domain; a request with no
locale reads it in English.
MishkaCmsCore.Runtime.Resources.Validations.SameSiteReference holds the two records to one site;
declare it before this one with only_when_valid?: true, so a record of another site gets its
message and not this one's.
Options
:field— required. The attribute holding the id.:resource— required. The resource the id names.:label— required. What the named record is called in the message, such as"section".:read_action— a read of the named resource that reaches every site's rows. Defaults to:master_get.:through— for a named record with noworkspace_version_idof its own, as a note:{field, resource}or{field, resource, read_action}, the attribute on it naming the record whose version it is in. Its read action defaults to:master_get.:in—:same_version(the default), or:other_versionfor a record of another version of the same workspace.
Usage
validate {SameWorkspaceVersion,
field: :parent_section_id, resource: MishkaDocument.Section, label: "section"},
only_when_valid?: true
validate {SameWorkspaceVersion,
field: :source_note_id,
resource: MishkaDocument.Note,
label: "note",
through: {:section_id, MishkaDocument.Section}},
only_when_valid?: true
validate {SameWorkspaceVersion,
field: :source_section_id,
resource: MishkaDocument.Section,
label: "section",
in: :other_version},
only_when_valid?: true