Skip to content

ModelUtils

Wyatt Greenway edited this page Nov 30, 2022 · 10 revisions

namespace ModelUtils

function parseQualifiedName(
    fieldName: string,
): object
📜

Parse a fully qualified field name.

A fully qualified field name is a field name that is prefixed by its parent model. For example, 'User:email' is a fully qualified field name, whereas just 'email' is not.

This method will actually parse both formats however. It will parse fully qualified field names, and short-hand field names (just the field name). If just a field name is provided with no model name prefix, then the resulting modelName property of the returned object will be undefined.

Field names themselves can be deeply nested. For example, 'User:metadata.ipAddress'. Field nesting was designed into the Mythix ORM framework, and is partially supported in some areas of the framework. However, field nesting likely won't work in many places without further support being added. This feature was left in-place for now, because it will likely be expanded upon in the future. Because of this "field nesting", instead of just one field name being returned, an array of field names is always returned. Generally, to get the field name you are looking for you would just get the first index (fieldNames[0]) on the returned object.

This method can and will also parse just a model name, so long as the provided name starts with an upper-case letter. If no colon is found (meaning no model prefix is present), then the provided value will be assumed to be a model name only if it starts with an upper-case letter. Otherwise, it is treated as a field name, and returned in the fieldNames array.

Arguments:

  • fieldName: string

    A model name, field name, or fully qualified field name to parse.

Return value: object

An object with the shape { modelName: string | undefined; fieldNames: Array<string> }. The modelName property will contain the name of the model for the field, if it is known, which will only be the case for a fully qualified name (i.e. 'User:email'), or a model name alone (i.e. 'User'). fieldNames will always be an array of field names parsed, which will generally only be one. It can be empty if no field name was provided, for example if only a model name was provided (i.e. 'User').


Clone this wiki locally