Introduction

Databases in Saturn are accessed through an active record pattern, with database schema being defined entirely through an XML based format. To create new database tables, simply create a schema.xml file alongside a controller, and write your model definitions as follows:

Entities

Tables are defined by entity elements, while columns are determined by children of said element. It is perfectly valid for entities to contain child entities — indicating a one-to-many/parent-child relationship between corresponding records.

/application/blog/schema.xml
<entity name="blogpost">
    <string name="title"/>
    <date name="post_date"/>
    <text name="content"/>
    <entity name="comment">
        <text name="content"/>
    </entity>
</entity>

You can add an order attribute to provide a default query sorting order.

/application/blog/schema.xml
<entity name="blogpost" order="post_date desc">
    <string name="title"/>
    <date name="post_date"/>
    <text name="content"/>
</entity>

Static entities

Use static instead of entity to define entities where all information will be stored in a single record (home page content, contact page details, …).

application/home/schema.xml
<static name="homepage">
    <string name="title"/>
    <text name="content"/>
</static>
Edit this page on GitHub Updated at Mon, Feb 14, 2022