Working With Entities
Entity classes can be named and namespaced however you want to set them
up within your project structure. For the following examples, the
Entities will just be prefixed with an
Entity namespace for easy psr-0
Defining An Entity
The minimal required definition of an entity defines the
$table and the
fields, and extends from
All of the DBAL
schema column options can be used for field attributes, and will be passed to DBAL when
creating the table structure through migrations. Spot adds some additional field attributes like
value as well.
In the above “Post” entity, the primary key is defined on the
'primary' => true attribute on the field definition. If the primary
key is also an auto-increment column, you must also add a
The full required definition looks like this:
An index can be defined on an entity field by adding the
'index' => true
Many times, it is desirable to create a compound index with more than one
column. In Spot, simply give the
index attribute a name that is shared with
another column, and a compound index will be created using all columns with the
same index name.
Similar to defining an index, you must add a
'unique' => true to specify a
single field as requiring a unique value:
And also just like normal indexes, compound unique indexes can be created by using a shared name:
unique. This happens in the
Spot\Mapperthat is run before every insert and update operation. This results in one extra query on insert or update for each unique column or compound column group.
A required field can be enforced on save, create, and update using a
'required' => true attribute.