Skip to content

Model Naming Conventions

KrisJordan edited this page Sep 13, 2010 · 10 revisions

In Recess! Models use a variation on the ActiveRecord pattern to provide an Object-Relational Mapping facility in the Recess Framework.

Model to Table

The assumed table name is the Model’s class name in lowercase. To override this add a !Table [table_name] annotation to your model. When providing your own name for the model be sure to follow the case-sensitivity expectations of your RDBMS & OS (MySql).

Example:


class Post extends Model {} // Table: post
class Person extends Model {} // Table: person

BelongsTo Relationship

Example:


/** !BelongsTo person */
class Post extends Model {}

class Person extends Model {}

// usage:
$post→person();

Variables used in table:
| Variable | Value |
| BelongsToName | person |

For Convention Example Override
Related Class ucfirst(BelongsToName) Person , Class: ClassName
Foreign Key BelongsToName . ‘Id’ personId , ForeignKey: ColumnName

Example using overrides:


/** !BelongsTo author, Class: Person, ForeignKey: personId */
class Post extends Model {}

class Person extends Model {}

// usage:
$post→author();

HasMany Relationship

Example:


/** !BelongsTo author, Class: Person, ForeignKey: personId */
class Post extends Model {}

/** !HasMany post */
class Person extends Model {}

// usage:
$person→post();

Variables used in table:
| Variable | Value |
| HasManyName | post |
| Class | Person |

For Convention Example Override
Related Class ucfirst(HasManyName) Post , Class: ClassName
Foreign Key lcfirst(Class) . ‘Id’ personId , ForeignKey: ColumnName

Example using overrides:


/** !BelongsTo author, Class: Person, ForeignKey: personId */
class Post extends Model {}

/** !HasMany posts, Class: Post, ForeignKey: postId */
class Person extends Model {}

// usage:
$post→author();

HasMany, Through Relationship

Clone this wiki locally