My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
NameConventionTables  
Lesson 2: Database setup
Updated Aug 25, 2009 by joomlafr...@gmail.com

Lesson 2: Database setup

Before we create any code we need to create tables in the database.

It's very important you follow the name convention of your table as in: http://blog.joomlatools.eu/2008/01/joomla-coding-practices-tables-and.html

example save as install.mysql.utf.sql in administrator/components/com_bib/install/

CREATE TABLE IF NOT EXISTS `#__bib_authors` (
  `bib_author_id` int(11) NOT NULL auto_increment,
  `name` varchar(250) NOT NULL,
  PRIMARY KEY  (`bib_author_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE `#__bib_books` (
  `bib_book_id` int(11) NOT NULL auto_increment,
  `bib_author_id` int(11) NOT NULL,
  `bib_genre_id` int(11) NOT NULL,
  `title` varchar(250) NOT NULL,
  `enabled` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`library_book_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8  ;

CREATE TABLE `#__bib_genres` (
  `bib_genre_id` int(11) NOT NULL auto_increment,
  `name` varchar(250) NOT NULL,
  PRIMARY KEY  (`library_genre_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

Primary keys and foreign keys are always named component_table_id. For instance bib_book_id or bib_author_id in the bib component.

The database tables are also named prefix_component_table (plural), for instance #__bib_books or #__bib_authors. The Name of the table start with the Joomla! prefix followed by the name of the component

It's a good idea to give the name of your tables a different name than the name of your your component

NOT SO GOOD name of the component: com_books, name of the table: books

#__books_books

BEST use a different name for your component (1 word!)

#__bib_books

----

NOT GOOD (will not work)

#__bib_books_authors

BETTER

#__bib_bookauthors

BEST

#__bib_authors

English Language

The framework understand (at this moment) only english so you need to write your table in english. You have to work with Singular (1 item) Plural (all items)

most of the time the difference in name is a "s" in english language

  • book - books
  • boat - boats
  • color - colors

But rememeber that the framework understand english, so plural is for some words different

  • category- categories
  • person-people
  • brewery- breweries
  • move- moves
  • sex- sexes
  • child- children
  • man- men
  • foot- feet
  • taxon- taxa
  • quiz- quizzes
  • child- children
  • ...

Look in the file plugins/system/koowa/inflector/inflector.php for the "Rules for pluralizing and singularizing of nouns."

You will notice also an array 'countable' These are words that are singular and plural the same time. Do not use these words for your table

            'countable' => array(
			'aircraft',
			'cannon',
			'deer',
			'equipment',
			'fish',
			'information',
			'money',
			'moose',
			'rice',
			'series',
			'sheep',
			'species',
			'swine',

However, you could override the behaviour by adding words:

KInflector::addWord('sheep', 'sheepsies');

But this is not recommended.


Sign in to add a comment
Powered by Google Project Hosting