Skip to content

EN:ModelConfiguration

Philipp Schüle edited this page Jul 26, 2018 · 1 revision

Table of Contents

Introduction

Beginning with Version Elena 2015.11.8dev1, we use doctrine/orm for schema creation and updates.

Mantis Issue

see 0011762: use doctrine for schema creation and update / https://forge.tine20.org/view.php?id=11762

Example of ModelConfiguration

Inventory_Model_InventoryItem:

   protected static $_modelConfiguration = array(
        'version'           => 7,
        'recordName'        => 'Inventory item',
        'recordsName'       => 'Inventory items', // ngettext('Inventory item', 'Inventory items', n)
        'containerProperty' => 'container_id',
        'titleProperty'     => 'name',
        'containerName'     => 'Inventory item list',
        'containersName'    => 'Inventory item lists', // ngettext('Inventory item list', 'Inventory item lists', n)
        'hasRelations'      => TRUE,
        'hasCustomFields'   => TRUE,
        'hasNotes'          => TRUE,
        'hasTags'           => TRUE,
        'modlogActive'      => TRUE,
        'hasAttachments'    => TRUE,
        'exposeJsonApi'     => TRUE,
        'createModule'    => TRUE,
        'appName'         => 'Inventory',
        'modelName'       => 'InventoryItem',
        'table'           => array(
            'name'    => 'inventory_item',
            'options' => array('collate' => 'utf8_general_ci'),
            'indexes' => array(
                'container_id' => array(
                    'columns' => array('container_id')
                )
            ),
        ),
        'fields'          => array(
            'name' => array(
                'type'        => 'string',
                'length'      => 255,
                'validators'  => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence' => 'required'),
                'label'       => 'Name', // _('Name')
                'queryFilter' => TRUE
            ),
            'status' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'nullable' => true,
                'label' => 'Status', // _('Status')
                'type' => 'keyfield',
                'name' => 'inventoryStatus',
            ),
            'inventory_id' => array(
                'type'       => 'string',
                'length'     => 100,
                'nullable'   => true,
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Inventory ID' // _('Inventory ID')
            ),
            'description' => array(
                'type'       => 'text',
                'nullable'   => true,
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      =>'Description' // _('Description')
            ),
            'location' => array(
                'type'       => 'string',
                'length'     => 255,
                'nullable'   => true,
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Location', // _('Location')
            ),
            'invoice_date' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Invoice date', // _('Invoice date')
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'hidden'     => TRUE,
                'default'    => NULL,
                'type'       => 'datetime',
                'nullable'     => true,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
            ),
            'total_number' => array(
                'type'         => 'integer',
                'nullable'     => true,
                'validators'   => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'        => NULL,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'default'      => 1,
            ),
            'active_number' => array(
                'type'         => 'integer',
                'nullable'     => true,
                'validators'   => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'        => 'Available number', // _(Available number)
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'default'      => 1,
            ),
            'invoice' => array(
                'type'       => 'string',
                'nullable'   => true,
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Invoice', // _('Invoice')
                'hidden'     => TRUE
            ),
            'price' => array(
                'type'         => 'float',
                'specialType'  => 'euMoney',
                'nullable'     => true,
                'validators'   => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'        => 'Price', // _('Price')
                'hidden'       => TRUE,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
            ),
            'costcentre' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Cost centre', // _('Cost Center')
                'hidden'     => TRUE,
                'type'       => 'record',
                'nullable'   => true,
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE, Zend_Filter_Input::DEFAULT_VALUE => NULL),
                'config' => array(
                    'appName'     => 'Sales',
                    'modelName'   => 'CostCenter',
                    'idProperty'  => 'id',
                ),
            ),
            'warranty' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Warranty', // _('Warranty')
                'hidden'     => TRUE,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'type'       => 'datetime',
                'nullable'   => true,
            ),
            'added_date' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Item added', // _('Item added')
                'hidden'     => TRUE,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'type'       => 'datetime',
                'nullable'   => true,
            ),
            'removed_date' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label'      => 'Item removed', // _('Item removed')
                'hidden'     => TRUE,
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                'type'       => 'datetime',
                'nullable'   => true,
            ),
            'deprecated_status' => array(
                'type'         => 'integer',
                'validators'   => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE, Zend_Filter_Input::DEFAULT_VALUE => 0),
                //'label'        => 'Deprecate', // _('Deprecate')
                'label'        => NULL,
                'default'      => false,
            ),
            'image' => array(
                'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE),
                'label' => 'Image', // _('Image')
                'inputFilters' => array('Zend_Filter_Empty' => NULL),
                // is saved in vfs, only image files allowed
                'type' => 'image'
            ),
        )
    );

HOWTO write update script / change schema

If yo need to change the schema, you have to increase the model version number by 1:

   protected static $_modelConfiguration = array(
        'version'           => 8,
        [...]
    )

and write an update script:

    public function update_0()
    {
       $this->updateSchema('Inventory', array('Inventory_Model_InventoryItem'));
        $this->setApplicationVersion('Inventory', '10.1');
    }

and increase the application version in setup.xml:

    <version>10.1</version>
You can’t perform that action at this time.