Skip to content

Todo list with Symfony 1.4 – Part 2 (Data Model)

February 15, 2011

The Data Model

Let’s analyze the schema.yml here. As always, even when Symfony 1.4 let’s you create the schema out of  the database, I got used to work from the schema perspective.

I mean, when you work from the schema, not only does it let you have a good view of the tables and fields but also a better design perspective of the relations among classes. So from my humble opinion, the schema is like a middle tier definition control area where you can modify up and down (up to the object model and down to the database model).

Let’s see our model for this app

schema.yml

Basically a user can have many lists, so please check the name of the relations section at the user definition: Mylists. This is important because when Symfony generates the source code, the collection of lists will be named: Mylists. The same thing happens when defining tasks in Mylist.

In addition, I think important to take the time to clearly specify the relations both ways, that is, the User‘s perspective on their lists and the Mylist‘s perspective on their user. This kind of discipline improves readability in the future and helps the source code generator engine.

Finally, a couple of comments. Firstly, notice that lists were named Mylist. This is because list is a PHP function so it could cause us a lot of trouble later. Secondly, as you may remember from specs, tasks should be able to be reordered. This is why I added a field named position to the Task class. But I also need that every time I ask for a list of tasks, they are displayed “sorted by position”. And here’s a little Doctrine trick, while defining the schema you can tell that a specific collection of data will be displayed following certain criteria. In this case, under the Tasks relation, in Mylist class, I typed: order by: position ASC.

Read Part 3

About these ads

From → symfony

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: