http://www.symfony-project.com/book/trunk/model
databse.yml
prod:
propel:
param:
host: mydataserver
username: myusername
password: xxxxxxxxxx
all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
host: localhost
database: blog
username: root
password:
compat_assoc_lower: true
# datasource: propel
# encoding: utf8
# persistent: true
schema.yml basic
propel:
blog_article:
_attributes: { phpName: Article }
id:
title: varchar(255)
content: longvarchar
created_at:
blog_comment:
_attributes: { phpName: Comment }
id:
article_id:
author: varchar(255)
content: longvarchar
created_at:
propel:
blog_article:
id: { type: integer, required: true, primaryKey: true, autoincrement: true }
name: { type: varchar , size: 50, default: foobar, index: true }
group_id: { type: integer, foreignTable: db_group, foreignReference: id, onDelete: cascade }
schema.yml syntax detail
The column parameters are:
- type: Propel column type. See Propel list of types for more details. The compact syntax (varchar(50)) is also supported as a type value.
- size: for VARCHAR type columns, the size of the string. Note that a column defined as varchar(50) in basic syntax is defined as { type: varchar , size: 50 } in extended syntax.
- required: false by default, set it to true if you want the column to be required
- default: default value
- primaryKey: boolean, to be set to true for primary keys
- autoincrement: boolean, to be set to true for columns of type integer that need to be auto-increment
- sequence: sequence name for databases using sequences for auto-increment columns (e.g. PostgreSQL or Oracle)
- index: boolean, to be set to true if you want a simple index or to unique if you want a unique index to be created on the column
- foreignTable: to create a foreign key to another table.
- foreignReference: the name of the related column if a foreign key is defined via foreignTable
- onDelete: if set to cascade for a foreign key, records in this table are deleted when a related record in the foreign table is deleted.
- isCulture: to be set to true for culture columns in localized content tables (see the internationalization chapter)
Type
boolean
integer
float
date >= 1970-01-01
bu_date
timestamp >= 1970-01-01
bu_timestamp
varchar(size) <= 256 characters
longvarchar <= 65kb
Schema conventions
Empty columns called id are considered to be primary keys.
Empty column ending with _id are considered to be foreign keys, and the related table is automatically determined according to the first part of the column name.
Empty columns called created_at are automatically set to the timestamp type.
For all these columns, you don't need to specify any type, since symfony will deduce their format from their name.
Foreign key
_foreign_keys:
my_foreign_key:
foreign_table: db_user
onDelete: cascade
references:
- { local: user_id, foreign: id }
- { local: post_id, foreign: id }
Index
propel:
blog_article:
id:
title: varchar(50)
created_at:
_indexes:
my_index: [title, user_id]
_uniques:
my_other_index: [created_at]
schema.xml
<?xml version="1.0" encoding="UTF-8"?>
<database name="propel" defaultIdMethod="native" noxsd="true">
<table name="blog_article" phpName="Article">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" size="255" />
<column name="content" type="longvarchar" />
<column name="created_at" type="timestamp" />
</table>
<table name="blog_comment" phpName="Comment">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="article_id" type="integer" />
<foreign-key foreignTable="blog_article">
<reference local="article_id" foreign="id"/>
</foreign-key>
<column name="author" type="varchar" size="255" />
<column name="content" type="longvarchar" />
<column name="created_at" type="timestamp" />
</table>
</database>