Difference between revisions of "Developers/Entities"

From PartKeepr Wiki
Jump to: navigation, search
(Created page with "= Introduction = PartKeepr uses [http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html Doctrine Entities] to map PHP objects to...")
(No difference)

Revision as of 16:41, 4 November 2015

Introduction

PartKeepr uses Doctrine Entities to map PHP objects to the database.

No manual database queries are required - all queries are handled by Doctrine. Custom queries must be written using DQL, the Doctrine Query Language.

Creating new entities and registering it with the REST API

In order to create a new entity, simply create an entity file as per Doctrine documentation. Then you need to register a Dunglas API resource in the app/config/config_partkeepr.yml file:

This is an example and the resource definition entry might change. Refer to the config_partkeepr.yml for up-to-date examples.
resource.part_manufacturer:
        parent:    "api.resource"
        arguments: [ "PartKeepr\\PartBundle\\Entity\\PartManufacturer" ]
        tags:      [ { name: "api.resource" } ]
        calls:
            -       method:    "initNormalizationContext"
                    arguments: [ { groups: [ "default" ] } ]
            -       method:    "initDenormalizationContext"
                    arguments:
                        - { groups: [ "default" ] }

ExtJS Model Syncing

The PartKeepr frontend uses ExtJS, a full-stack JavaScript framework. ExtJS allows PartKeepr to operate on entities (called models in ExtJS) and relations. PartKeepr generates the ExtJS Model files for you.

This means that if you create or change any Doctrine Entity, you need to execute the following command:

php app/console generate:extjs:entities

That command extracts all fields and relations from your entity and generates a model file.

Virtual Fields

Sometimes you need to pass fields over the REST API which shouldn't persisted to the database. For that purpose, you can use the @VirtualField annotation on any property:

class MyEntity
{
   /**
    * @VirtualProperty(type="string")
    */
   protected $myVirtualField;
}

The ExtJS entity generator then puts additional fields in the resulting model file.