Table of Contents
The Recess Framework includes a web app to aid development called 'Recess Tools'. Generating new Models for an application and creating corresponding tables in the database is quick work. By browsing to your application and selecting 'new' Model you'll be taken to the new Model helper. After providing a name, table information, and properties the model and, if needed, table will be generated.
A quick peak at the code generated for
Post:
Example 12.1.
Post
is simple Recess
Model
<?php /** * !Database Default * !Table posts */ class Post extends Model { /** !Column PrimaryKey, Integer, AutoIncrement */ public $id; /** !Column String */ public $title; /** !Column String */ public $body; /** !Column Integer */ public $authorId; }?>
Lots of annotations! Why so many? Being explicit is a good thing- especially when you don't have to do any of the extra writing. Starting from the top: the Database annotation is what allows Recess to have Models from multiple data sources in a single app. The Table annotation is straightforward: the name of the table in the database the Model maps to. Following is a HasMany relationship using a join table with the Through argument. For Rails folks this should look decently familiar. More to come on relationships.
Each property uses a
!Column
annotation to provide additional semantic typing information.
Specifying properties and column mappings is optional in Recess but
it is encouraged for three reasons. One, you can look at a Model's
code and know exactly which properties are available. This is
different from Rails or Cake
models. Two, Recess checks to ensure your annotations and the
database types match. Three, Recess can regenerate tables from Models
marked up with annotations.