Naming Conventions

Naming conventions

Controller

Convention is to use the plural form of the model name when applicable, e.g. stories controller, authors controller

  • Says what to do and where to do it. Has logic like “if post is not valid, send error about validation”
  • Prepares variable for view from model
    • Create variable of tables using things like the find('all') command in the API

Action Controller and Helper Methods

Action Controller and Helper methods are named where all letters are lowercase and words are separated by underscores, e.g. list_all, textilize

Private methods start with an underscore.

Model

Singular, first letter Capitalized, CamelCase for models like SteeringWheel

Validation of data is here.

Relationships between various tables

Model files have information in them which appears like belongs_to and has_many and reflects automatic connections made by Akelos, using fields like author_id in a story table

  • belongs_to - a Story model belongs_to an Author. When a table is linked to another table with belongs_to, you can refer to fields in that table by appending the relationship name to the class name. E.g., if product belongs_to category, then in a view that deals with product you can get the category name with $Product→category→name.
  • has_many - an Author has_many Stories

Plurality matters. Be very careful – Akelos does stuff with making this singular and plural again, so make sure you are including the appropriate number of s

View

How things look - Akelos in html ⇒ tpl

  • Uses variables in Controller and prints them
  • Get variable from controller replacing $this→ symbol with $ ( Ex. $this→movies in bob_controller action submit ⇒ allows submit.tpl to access something called $movies )
  • The scaffolding creates edit, show, and delete links in list views. To replace the text 'show' with another field in the list view, do this
   <?= link_to($product->name, 'action' => 'show', 'id' => $product->id ?>

Database Table (schema)

Table names need to be plural, with underscores instead of spaces between words, like steering_wheels, invoice_items, orders.

Akelos handles creation date/time and update date/time out of the box, so there is no need to code it yourself. Handling dates and searching through ranges might be tricky, if you use the Akelos conventions this comes for free.

By convention if you add a column named “created_at” or “updated_at” it will handle those fields for you automatically and if you name a column in a migration like “posted_at” it will set the field type and length for you, in this case, datetime. If you use “created_on” it will use just “date”.

Column Data Types

Akelos natively supports the following column data types:

  • integer|int, float, decimal
  • string, text
  • datetime|timestamp, date
  • binary
  • boolean

Caution: Because boolean is virtual tinyint on mysql, you can't use tinyint for other things!

column_name default setting usage
id integer not null auto_increment primary_key Primary key
*_id,*_by integer index Foreign key
description,content,body text
position integer index
*_count integer default 0
lock_version integer default 1
*_at datetime created_at, updated_at,…
*_on date starts_on, ends_on,…
is_*,has_*,do_*,does_*,are_* boolean not null default 0 index
*somename multilingual column ⇒ en_somename, es_somename
default string

Primary Key

The primary key of a table is assumed to be named id.

Foreign Key

The foreign key is named with the singular version of the target table name with _id appended to it, e.g. order_id in the items table where we have items linked to the orders table.

Many to Many Link Tables

Tables used to join two tables in a many to many relationship is named using the table names they link, with the table names in alphabetical order, for example items_orders.

Automated Record Timestamps

You can get ActiveRecord to automatically update the create and update times of records in a database table. To do this create two specially named columns created_at and updated_at to your table. If you only want to store the date rather than a date and time, use created_on and updated_on.

Classes

Classes use MixedCase and have no underscores, each word starts with a uppercase letter, e.g. InvoiceItem

Files, Directories and other pluralization

Files are named using lowercase and underscores. Assuming we have an Orders controller then the following other conventions will apply:

  • That there is a helper module named OrdersHelper in the orders_helper.php found in the app/helpers directory
  • Akelos will look for view template files for the controller in the app/views/orders directory
  • Output from this view will then be used in the layout defined in the orders.php in the app/views/layouts directory
 
naming-conventions.txt · Last modified: 2009/12/29 18:27 by inex
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki