Meet schema.yml
Until today, Propel integration in symfony implied that your database schema had to be defined in XML files called schema.xml
. For instance, the database schema of the first project tutorial looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<database name="propel" defaultIdMethod="native" noxsd="true">
<table name="weblog_post" phpName="Post">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" size="255" />
<column name="excerpt" type="longvarchar" />
<column name="body" type="longvarchar" />
<column name="created_at" type="timestamp" />
</table>
<table name="weblog_comment" phpName="Comment">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="post_id" type="integer" required="true" />
<foreign-key foreignTable="weblog_post">
<reference local="post_id" foreign="id"/>
</foreign-key>
<column name="author" type="varchar" size="255" />
<column name="email" type="varchar" size="255" />
<column name="body" type="longvarchar" />
<column name="created_at" type="timestamp" />
</table>
</database>
We thought that, for a framework trying to be as simple as possible, it was not the best we could do. As a matter of fact, quite a number of symfony beginners were afraid about its configuration specifically because of this XML file. Some of them were even caught quitting at that point, when they thought that learning a new syntax for schema files was too much for a first try.
So we made it possible to write database schemas in YAML format. You know how we like this format: It's easy to read and write, it's simple to understand, and it's fun. So for instance, the first project tutorial schema (soon to be updated in the doc) can now look like this:
propel:
weblog_post:
_attributes: { phpName: Post }
id:
title: varchar(255)
excerpt: longvarchar
body: longvarchar
created_at:
weblog_comment:
_attributes: { phpName: Comment }
id:
post_id:
author: varchar(255)
email: varchar(255)
body: longvarchar
created_at:
Nothing more. Save this into a schema.yml
file in your project config/
folder, then run
$ symfony propel-build-model
...and the Propel model classes are generated just as before.
Of course, to make it simple, we added some magic to it. If you follow the conventions, you don't need to write too much configuration (does that ring a bell?). For instance, if your primary key is called id
, then symfony will automatically make it an autoincrement integer. If a field ends with _id
, then symfony will recognize a foreign key and enrich the schema as you expect it to. Fields called created_at
or updated_at
are, of course, of type timestamp
, so you don't need to specify it. I18N tables will be recognized as such, as long as their name end with _i18n
.
There will soon be a full documentation about it, but until then, we invite you to try this new feature and give us your feedback. It is available since the release 1577 in the SVN trunk.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Your own XML files will be processed as well, just as before.
<column name="id" type="integer" required="true" autoincrement="true" primarykey="true" />
<column name="type" type="integer" inheritance="single">
<inheritance key="1" class="Customer" extends="Person"/>
<inheritance key="2" class="Delivery" extends="Person"/>
</column>
<column name="name" type="varchar" size="255" />
<column name="created_at" type="timestamp" />
<column name="updated_at" type="timestamp" />
</table>
here is the question , how to achieve propel inheritance with this yaml description? is it possible?