-
Notifications
You must be signed in to change notification settings - Fork 3
Entities
An entity is a persistent Actionscript object - that is to say an object which is capable of being loaded and saved to the database using Flextrine. Entities are defined in PHP within your Flextrine server-side component, and then their matching AS3 classes are generated using the console tool.
Entities are defined using one of Doctrine 2's drivers - at present it supports a docblock annotations driver, an XML driver, a YAML driver and a PHP driver. All examples in Flextrine's documentation use the annotations driver, but Flextrine supports all Doctrine's drivers (in particular the XML and YAML drivers are useful if you use a tool such as ORM Designer which only outputs XML and YAML). In order to change drivers edit the metadata
section of your application config.yml
file.
In most normal situations I would recommend using the annotations driver, which is Flextrine's default.
The following links give excellent information about creating entities and creating associations between entities. Since v0.9 Flextrine supports all property and association types.
A basic entity might look something like this:
<?php
namespace vo;
/**
* @Entity
*/
class Doctor {
/** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */
public $id;
/** @Column(length=100, type="string") */
public $name;
}
There are a few things that are special about Flextrine entities compared to normal Doctrine 2 entities:
All persistent properties in your entity must be public. This actually goes against Doctrine 2 best practices, but is absolutely necessary for Flextrine to work.
For the moment the primary key should always be called id
. This requirement will be relaxed in a future version of Flextrine.
Although since v0.9 Flextrine does support server-side cascades to some degree this feature is experimental and you use cascades at your own risk!
When you generate the matching AS3 entities using the console tool, two classes are created for each entity - in our example vo.DoctorEntityBase and vo.Doctor will be created. The DoctorEntityBase is Doctor's parents, and contains the bits that make Flextrine go. The reason there are two classes per entity rather than just one is to allow you to regenerate entities without losing any business logic you may have placed in the main entity class.