Symfony Database Schema Php5

ADVERTISEMENT

symfony
Open-Source PHP5 MVC Framework
Agile Development
MODEL
DATABASE SCHEMA
The database schema is a description of the relational model to do the
ORM
.
connection attributes
Y
ou define the tables, their relations, and the characteristics of their columns.
noXsd -
Symfony's syntax for schemas uses the YAML format.
Set it to false if you want your schema to be
validated before code generation takes place.
Symfony also understands the Propel native XML schema format
defaultIdMethod
- If none is provided, then the database's
schema.yml
native method of generating IDs will be used--for example,
autoincrement for MySQL, or sequences for PostgreSQL.
located in myproject/config/
The other possible value is none.
package
- is like a namespace; it determines the path where
the first key represents a connection name
the generated classes are stored. It defaults to lib/model/,
but you can change it to organize your model in subpackages.
propel:
_attributes:
{noXsd: false, defaultIdMethod: none, package: lib.model}
blog_article:
_attributes: { phpName: Article }
id:
{required: true, primaryKey: true, autoIncrement: true}
title:
varchar(255)
content:
longvarchar
tables
created_at:
name:
{type: varchar(50), default: foobar, index: true}
group_id: {type: integer, foreignTable: db_group, foreignReference: id}
blog_comment:
column attributes
_attributes: { phpName: Comment }
type
- Column type. The choices are boolean, tinyint,
id:
smallint, integer, bigint, double, float, real, decimal,
char, varchar(size), longvarchar, date, time, timestamp,
article_id:
bu_date, bu_timestamp, blob, and clob.
author:
varchar(255)
required
- Boolean. Set it to true if you want the
column to be required.
content:
longvarchar
default
- Default value.
created_at:
table attributes
primaryKey
- Boolean. Set it to true for primary keys.
phpName
- the name of the class
that will be generated. If you don't
autoIncrement
- Boolean. Set it to true for columns
empty column type
mention a phpName for a table, the
of type integer that need to take an auto-incremented
Empty columns named id are considered PKs
name will be the camelCase version
value.
of the table name.
id: { type: integer, required: true,
sequence
- Sequence name for databases using
primaryKey: true, autoIncrement: true}
sequences for autoIncrement columns (for example,
isI18N
- Boolean. Set it to true for
PostgreSQL and Oracle).
i18n
Empty columns named XXX_id are
considered foreign keys
index
- Boolean. Set it to true if you want a simple
i18nTable
- name of the i18n table.
foobar_id: {type: integer, foreignTable:
index or to unique if you want a unique index to be
db_foobar, foreignReference: id}
created on the column.
Indexes and Unique Indexes
foreignTable
Alternative Syntax
- A table name, used to create a foreign
Empty columns named created_at,
propel:
key to another table.
updated at, created_on and updated_on are
blog_article:
considered dates and automatically take the
foreignReference
- The name of the related column
id:
timestamp type
if a foreign key is defined via foreignTable.
title:
varchar(50)
created_at: { type: timestamp }
created_at:
onDelete
- Determines the action to trigger when a
updated_at: { type: timestamp }
_indexes:
record in a related table is deleted. When set to set
my_index:
[title, user_id]
null, the foreign key column is set to null. When set
_uniques:
to cascade, the record is deleted. If the database
my_other_index: [created_at]
engine doesn't support the set behavior, the ORM
i18n
emulates it. This is relevant only for columns bearing
Tables that contain localized content
a foreignTable and a foreignReference.
Implied i18n
Explicit i18n Mechanism
isCulture
- Boolean. Set it to true for culture columns
Mechanism
propel:
in localized content tables.
db_group:
propel:
_attributes: { isI18N: true, i18nTable: db_group_i18n }
db_group:
Foreign Key Alternative Syntax Applied to
id:
id:
Multiple Reference Foreign Key
created_at:
created_at:
_foreignKeys:
my_foreign_key:
db_group_i18n:
db_group_i18n:
foreignTable: db_user
id:
{ type: integer, required: true, primaryKey: true,
name:
varchar(50)
onDelete:
cascade
foreignTable: db_group, foreignReference: id, onDelete: cascade }
references:
culture: { isCulture: true, type: varchar(7), required: true,primaryKey: true }
- { local: user_id, foreign: id }
name:
varchar(50)
- { local: post_id, foreign: id }
This cheat-sheet is not an official part of the symfony documentation

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go