Abstract class Phalcon\Mvc\Model\MetaData

implements Phalcon\Di\InjectionAwareInterface

Because Phalcon\Mvc\Model requires meta-data like field names, data types, primary keys, etc. this component collect them and store for further querying by Phalcon\Mvc\Model. Phalcon\Mvc\Model\MetaData can also use adapters to store temporarily or permanently the meta-data. A standard Phalcon\Mvc\Model\MetaData can be used to query model attributes:

  1. <?php
  2. $metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
  3. $attributes = $metaData->getAttributes(new Robots());
  4. print_r($attributes);

Constants

integer MODELS_ATTRIBUTES

integer MODELS_PRIMARY_KEY

integer MODELS_NON_PRIMARY_KEY

integer MODELS_NOT_NULL

integer MODELS_DATA_TYPES

integer MODELS_DATA_TYPES_NUMERIC

integer MODELS_DATE_AT

integer MODELS_DATE_IN

integer MODELS_IDENTITY_COLUMN

integer MODELS_DATA_TYPES_BIND

integer MODELS_AUTOMATIC_DEFAULT_INSERT

integer MODELS_AUTOMATIC_DEFAULT_UPDATE

integer MODELS_DEFAULT_VALUES

integer MODELS_COLUMN_MAP

integer MODELS_REVERSE_COLUMN_MAP

Methods

final protected _initialize (unknown $model, unknown $key, unknown $table, unknown $schema)

Initialize the metadata for certain table

public setDI (unknown $dependencyInjector)

Sets the DependencyInjector container

public Phalcon\DiInterface getDI ()

Returns the DependencyInjector container

public setStrategy (unknown $strategy)

Set the meta-data extraction strategy

public Phalcon\Mvc\Model\MetaData\StrategyInterface getStrategy ()

Return the strategy to obtain the meta-data

final public array readMetaData (unknown $model)

Reads the complete meta-data for certain model

  1. <?php
  2. print_r($metaData->readMetaData(new Robots());

final public mixed readMetaDataIndex (unknown $model, unknown $index)

Reads meta-data for certain model using a MODEL_* constant

  1. <?php
  2. print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name')));

final public writeMetaDataIndex (unknown $model, unknown $index, unknown $data)

Writes meta-data for certain model using a MODEL_* constant

  1. <?php
  2. print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name')));

final public array readColumnMap (unknown $model)

Reads the ordered/reversed column map for certain model

  1. <?php
  2. print_r($metaData->readColumnMap(new Robots()));

final public readColumnMapIndex (unknown $model, unknown $index)

Reads column-map information for certain model using a MODEL_* constant

  1. <?php
  2. print_r($metaData->readColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP));

public array getAttributes (Phalcon\Mvc\ModelInterface $model)

Returns table attributes names (fields)

  1. <?php
  2. print_r($metaData->getAttributes(new Robots()));

public array getPrimaryKeyAttributes (unknown $model)

Returns an array of fields which are part of the primary key

  1. <?php
  2. print_r($metaData->getPrimaryKeyAttributes(new Robots()));

public array getNonPrimaryKeyAttributes (unknown $model)

Returns an array of fields which are not part of the primary key

  1. <?php
  2. print_r($metaData->getNonPrimaryKeyAttributes(new Robots()));

public array getNotNullAttributes (unknown $model)

Returns an array of not null attributes

  1. <?php
  2. print_r($metaData->getNotNullAttributes(new Robots()));

public array getDataTypes (unknown $model)

Returns attributes and their data types

  1. <?php
  2. print_r($metaData->getDataTypes(new Robots()));

public array getDataTypesNumeric (unknown $model)

Returns attributes which types are numerical

  1. <?php
  2. print_r($metaData->getDataTypesNumeric(new Robots()));

public string getIdentityField (unknown $model)

Returns the name of identity field (if one is present)

  1. <?php
  2. print_r($metaData->getIdentityField(new Robots()));

public array getBindTypes (unknown $model)

Returns attributes and their bind data types

  1. <?php
  2. print_r($metaData->getBindTypes(new Robots()));

public array getAutomaticCreateAttributes (unknown $model)

Returns attributes that must be ignored from the INSERT SQL generation

  1. <?php
  2. print_r($metaData->getAutomaticCreateAttributes(new Robots()));

public array getAutomaticUpdateAttributes (unknown $model)

Returns attributes that must be ignored from the UPDATE SQL generation

  1. <?php
  2. print_r($metaData->getAutomaticUpdateAttributes(new Robots()));

public setAutomaticCreateAttributes (unknown $model, unknown $attributes)

Set the attributes that must be ignored from the INSERT SQL generation

  1. <?php
  2. $metaData->setAutomaticCreateAttributes(new Robots(), array('created_at' => true));

public setAutomaticUpdateAttributes (unknown $model, unknown $attributes)

Set the attributes that must be ignored from the UPDATE SQL generation

  1. <?php
  2. $metaData->setAutomaticUpdateAttributes(new Robots(), array('modified_at' => true));

public array getDefaultValues (unknown $model)

Returns attributes (which have default values) and their default values

  1. <?php
  2. print_r($metaData->getDefaultValues(new Robots()));

public array getColumnMap (unknown $model)

Returns the column map if any

  1. <?php
  2. print_r($metaData->getColumnMap(new Robots()));

public array getReverseColumnMap (unknown $model)

Returns the reverse column map if any

  1. <?php
  2. print_r($metaData->getReverseColumnMap(new Robots()));

public boolean hasAttribute (unknown $model, unknown $attribute)

Check if a model has certain attribute

  1. <?php
  2. var_dump($metaData->hasAttribute(new Robots(), 'name'));

public boolean isEmpty ()

Checks if the internal meta-data container is empty

  1. <?php
  2. var_dump($metaData->isEmpty());

public reset ()

Resets internal meta-data in order to regenerate it

  1. <?php
  2. $metaData->reset();