Monday, January 28

ActiveRecord Databases - I

One of the main features that rails do support on is Convention over Configuration. Well repeat again and again Convention over Configuration. Let it get into the minds!
Well it is spread across the rails framework with which will be developing an application. I will be reminding whenever it's put in use.
In previous post, I did stress on how simple it would be in configuring the databases and tables with your application. In Java based applications, this would be done using lot of xml files, which is of course, time taking, lot of repetitive work and error prone... (at least that's what my friend's used to say!).

Well in rails this is not the case a simple convention that you follow would ensure of configuring the tables of databases.
"You name the tables in database as plurals and create classes with singular form of the table names."
Configuring the Databases:
The choice of which database you use the configuration and respective adapter would depend on. When we created an application, there is a set of predefined folders created over a simple command! (I will touch upon this later). "config" is one such folder and under this we will now concentrate/repair on "database.yml".
Rails would automatically create 3 different environments:
  1. Development
  2. Test
  3. Production
Based on the environment we work on we need to edit the data accordingly. (More on environments will be covered sooner!)
This file contains the information relate to the adapter, database, user credentials, host, port...

This does make sense in a way, the plural form for tables will fit as it contains huge data and the respective class which we would be placed under app/models, with the extension ".rb" is named in singular form.


development:
adapter: mysql
database: dummy
username: root
password:
host: localhost

What it means?
Our application is connected to MySQL database by name dummy, user being and root and with an empty password. The host environment is "localhost".

To Be Continued...

No comments: