CMDB Record References Developer Guide - edmozley/freeitsm GitHub Wiki
Since 5.3.0 ยท #312 ยท User guide: CMDB ยท Related: CMDB foundations, Analysts leaving
A CMDB property used to reference only another CI (object_ref), so an Owner was a "Person" CI kept by hand beside the real person - the demo data and Suggest with AI even created a Person class to make it work. Seven property types now point at the records FreeITSM already holds:
| Type | Table | Which records a CI may point at |
|---|---|---|
person |
users |
the CI's own company |
analyst |
analysts |
any active analyst |
team |
teams |
any active team |
location |
asset_locations |
the CI's own company, or a location shared by every company |
company |
tenants |
any company the person editing can reach |
supplier |
suppliers |
any active supplier |
contract |
contracts |
the CI's own company |
| File | Role |
|---|---|
includes/cmdb_record_refs.php |
The one place that knows those tables. cmdbRecordTypes() (table, name SQL, active SQL, scope, link), cmdbRecordScopeSql(), cmdbRecordSearch(), cmdbRecordAllowed(), cmdbRecordResolve(), cmdbRecordReferences(), cmdbRecordRefsReady(), and the TypedFields ref kinds |
cmdb_object_properties.value_ref_id |
The stored id. No FK - one column, seven tables; the property's type says which |
includes/typed_fields.php |
refSlot(): a ref definition may name its own storage slot (ref_slot) |
includes/services/cmdb.php |
classDefs() maps the record types to ref + kind + ref_slot 'record'; valueSchema() adds 'record' => 'value_ref_id' once the column exists; assertRecordRefsAllowed() on create and update |
api/cmdb/search_records.php |
The picker (by CI, asset, company or the active company) |
api/cmdb/record_references.php |
"Which CIs point at this record" - for delete dialogs |
api/cmdb/get_object.php, cmdb/object.js
|
value_record {id, name, state, url}; display and the inline picker |
cmdb/browse.js, assets/js/ci-asset-link.js
|
Required record properties on New CI and Create linked CI |
api/cmdb/save_class_property.php |
The types; refuses a type change that would misread stored values |
api/cmdb/_ai_helpers.php, ai_suggest_properties.php
|
The AI may suggest the record types, and is told to prefer them |
includes/cmdb_audit.php |
cmdbAuditRemovedRecords() - Data quality's References to removed records
|
includes/analyst_lifecycle.php |
analyst properties are a setup reference |
includes/cmdb_summary_prompt.php |
Names in the AI summary |
api/v1/resources/cmdb.php, lib/openapi_schemas.php
|
value_record / CmdbRecordRef
|
tests/cmdb-record-refs.php |
37 checks |
value_object_id has an FK to cmdb_objects and about eight readers that assume the id there is a CI without checking the property type - the impact walk's "referenced by property", the summary prompt's inbound references, the audit's disconnected, the network mapper's neighbours, deleteObject()'s clean-up. A person id stored there would be read as a CI with the same id. Hence the second column, and the engine change in ยง3.
TypedFields had one storage class for references, ref. A definition can now name another slot of the schema's columns:
// includes/services/cmdb.php - classDefs()
'type' => 'ref',
'ref_kind' => $record['kind'], // 'user', 'analyst', 'team', 'location', 'tenant', 'supplier', 'contract'
'ref_slot' => 'record', // -> valueSchema()['columns']['record'] = 'value_ref_id'
'record_type' => 'person',coerce() writes $out[refSlot($def)] and readValues() reads from the same slot. Asset custom fields set no ref_slot and are unchanged.
Before Database Verification the column does not exist: valueSchema() leaves the record slot out (so every other property reads and saves as before) and assertRecordRefsAllowed() refuses a record value with "run Database Verification".
Checked on every save (UI and REST, both through CmdbService::saveObject()), on every install:
-
Company, by
scope:ci_company=COALESCE(r.tenant_id, default) = the CI's company(NULL means the Default company's for these tables, never "shared");ci_company_or_sharedaddsOR r.is_shared = 1;reachable= the actor'scompanyScope(null = all). -
In use: an inactive team, analyst, supplier, contract or company is refused as a new value - but the value already stored passes (
$alreadyStored), so re-saving a CI never fails over an untouched retired supplier.
The picker (cmdbRecordSearch()) applies the same SQL, so it only offers what the save would accept.
Returns [id => {name, state, url}] with state:
| state | When | Shown as |
|---|---|---|
ok |
the name, a link if the record has a page (entityLink()) |
|
inactive |
the record's active flag is off | the name + (inactive) |
removed |
no such row | (removed) |
hidden |
in a company the viewer cannot reach | (another company) - never the name |
A location's name is its full path (UK > London > Floor 2).
Allowed (Ed, 2026-11-14). The id stays, the CI says (removed), and:
- the delete dialogs for a person, team, location, supplier and contract first show who points at it -
api/cmdb/record_references.phpโcmdbRecordReferences(), CI names only for companies the person deleting can reach, the rest counted; - Data quality โ References to removed records lists every such CI;
- an
analystproperty is inanalystReferenceRegistry()assetup, narrowed withproperty_id IN (SELECT ... WHERE property_type = 'analyst'), so the leaving checks list it and Delete waits until it is handed on.
save_class_property.php refuses a type change when values exist and the new type would keep them somewhere else, or keep the id but read it as something else (propertyValueHome(): text and dropdown share a home; each record type is its own). Person โ Team would otherwise turn every person id into a team id.
CMDB_AI_PROPERTY_TYPES includes the record types and the prompt says to use them for people, teams, places, companies, vendors and contracts - object_ref only for another CI. The wizard's "auto-create the target class" step therefore only runs for genuine CI references.
FREEITSM_TEST_DATABASE=freeitsm_prtest FREEITSM_TEST_URL=http://localhost/freeitsm-prtest php tests/cmdb-record-refs.php
A ZZ second company and records in both. Each refusal has a positive control. It needs value_ref_id (Database Verification) and skips without it.
One entry in cmdbRecordTypes(), a cmdb.record.type_<key> string, the OpenAPI enums, and - if the record can be deleted - the summary in its delete dialog.