-
Notifications
You must be signed in to change notification settings - Fork 65
Model Naming Conventions
In Recess! Models use a variation on the ActiveRecord pattern to provide an Object-Relational Mapping facility in the Recess Framework.
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
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();
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();