API Documentation for: 1.1.1
Show:

ObjectServiceField Class

Namespace: Canteen\Services

A custom field is used by the ObjectService class to represent property and db field definitions

Constructor

ObjectServiceField

(
  • id
  • [type=null]
  • [name=null]
)

Parameters:

  • id String

    The name of the database field

  • [type=null] RegExp | Array optional

    The validation type or set of items to match, default is no validation

  • [name=null] String optional

    The property name

Methods

__toString

() String

Represent the query as a SQL statement

Returns:

String:

The query in SQL string form

fieldToProperty

(
  • id
)
String static

Convert a mysql field (eg. content_id) to property (e.g. contentId)

Parameters:

  • id String

    The input field name (lowercase, comma separated)

Returns:

String:

The property name (lower, camel-cased)

option

(
  • property
  • value
)
ObjectServiceField private

Set an option

Parameters:

  • property String

    Either type, name, isIndex, select, prepend

  • value Mixed

    The value of the property to set

Returns:

ObjectServiceField:

Return the field for chaining

setDefault

(
  • [isDefault=true]
)
ObjectServiceField

Set the default index, e.g., instead of calling getItemById, you can do getItem

Parameters:

  • [isDefault=true] Boolean optional

    If the field is the default index

Returns:

ObjectServiceField:

Return the field for chaining

setIndex

(
  • [isIndex=true]
)
ObjectServiceField

Set the field to be an index, a method can be called, getItemsByName, where name is the indexed field. Database should also consider this an index.

Parameters:

  • [isIndex=true] Boolean optional

    If the field is index

Returns:

ObjectServiceField:

Return the field for chaining

setOrderBy

(
  • [orderBy='asc']
)
ObjectServiceField

If we should sort collection selects by this property.

Parameters:

  • [orderBy='asc'] String optional

    The string to prepend to result value

Returns:

ObjectServiceField:

Return the field for chaining

setPrepend

(
  • prepend
)
ObjectServiceField

Prepend this item with a string, useful for prepending full file path to a file name stored in the database.

Parameters:

  • prepend String

    The string to prepend to result value

Returns:

ObjectServiceField:

Return the field for chaining

setSelect

(
  • select
)
ObjectServiceField

Set a custom SQL select for this item

Parameters:

  • select String

    The SQL select entry that returns this item by name

Returns:

ObjectServiceField:

Return the field for chaining

Properties

id

String

The database field name

isDefault

Boolean

The default index such as the 'id' field

Default: false

isIndex

Boolean

If the property can be index for a select

Default: false

orderBy

String

If we should sort queries by this field, null is no sort, can either be desc or asc

Default: null

prepend

String

The prepend mapping for the bind, useful for prending a path to a file name

property

String

The property name on the final bind object

select

String

The select property for doing a mysql select

type

RegExp | Array

The validation type to use for this field