Tuesday, February 26

Ruby on Rails relevance to Startups - @ BarCamp

The barcamp5 hosted by Google Engineering Hyderabad :)
Many bloggers had already spoken their part about the proceedings through live blogging.
In brief, there was bit chaos on arranging things, running the talks/session parallely, and finally it was more like session with less user participation (devitation from what usual BarCamp famous for!!!)

Sumanth Krishna @ Ruby on Rails Conferences/Communities


I wanted to present on my favorite Ruby on Rails and since BarCamp is the place where lot of young minds, entrepreneurs... assemble. So I related it (RoR) to Startups and on "Ruby on Rails relevance to Startup's". I started the session post lunch around 3PM. I did present my views on very well about the startups and when the slides related to Ruby on Rails started, I just carried away more in explaining the details of RoR.


Slides: "RoR relevance to Startups" @ Google sponsored BarCamp5 :)
Scribd
SlidShare


Please feel free to enhance/comment on the presentation.
I am planning for a Workshop on Ruby on Rails with support of Twincling society :-)

Wednesday, February 13

Relationships between tables - How ActiveRecord handles?

Keywords:
  • has_one,
  • belongs_to,
  • has_many,
  • has_and_belongs_to_many
  • polyphormic
  • one-to-one
  • one-to-many
  • many-to-many
It's known that any web application will contain bunch of tables and they are dependent on each other. With normalization as the key, we avoid redundancy and have more relationships with tables using keys. In database terms, the following are the relations allowed/known between tables -> one-to-one, one-to-many, many-to-many. Let us digg more, how ActiveRecord handles these.
ActiveRecord supports the above mentioned relations and in fact, comes with set of key words which are easy to use, understand and pretty clean.
Let me take few snapshots from David's book:
Note:
  1. invoices is the table name
  2. orders is the table name
In the above snaphot, the motive is to declare the relationship between the orders and invoices tables. It's clear that orders will have invoices, i.e., invoices belong to orders. And watch out we will be using same words. Now to have the relationship declared, we will go to their models (Remember: the application access the tables through model so it makes sense to declare relationships also in models).

Now I am into order model, orders having invoices. so the key word that we use here is has_one and then followed by the model name (Note: It is not table name, this is not plural).
has_one :invoice

Next will go to invoice model, since invoices belongs to orders we use the key word belongs_to and then followed by the model name.
belongs_to :order

Well there is not xml written for models, no xml written for relationships. But simple convention and defined keywords done the job for us.
And as you might have guessed the has_many comes into use when the orders table is having relationship with one more table (say, line_items). The below snapshot will help you to understand the syntax and it's usage.

Will look into other keywords and other relationship in the following posts...

Thursday, February 7

Hyderabad hosts BarCamp5


BarCamp what is it?
BarCamp is an international network of user generated conferences — open, participatory workshop-events, whose content is provided by participants — often focusing on early-stage web applications and related open source technologies...
and the u can read more from here...

As part of series of BarCamp, this series is held @ Hyderabad. Into details....

Theme: Social web and beyond

Technologies, demos and startups- betting on Web2.0, Social web, Semantics Web and beyond!
Entrepreneurship
Social Web and Beyond
Opensource and Emerging Technologies
Product/Prototype/Idea Demos



On February 16th, 2008. Saturday

Venue ( Map of the venue )
Block 1, DivyaSree Omega
Survey No. 13, Kondapur Village,
Hyderabad, A.P 500 032
India.

Register @ Barcamp and hope to meet you there!
@ Orkut
@ Facebook

Spread the word and get the most of it!

Monday, February 4

ActiveRecord - Pluralization convention

In the previous post, we had seen how simply we had connected our database to the application. Now let us look in to another convention wherein, you need not have a xml file to connect each table in the database to the classes (Note: class is the blue print from where we create objects) in our application.
The convention here followed is English way of singular and plural forms. The database is nothing but collection of records, data in specific structure. And a 'class' as per Object Oriented Paradigm, it is a constructor and you can have multiple objects of similar type from it!
So it absolutely makes sense to name our tables in plural form (collection of data) and a class in the singular form.
Rails just does that! we name the tables of database as plurals and the respective classes as singular form of the same.

The above snapshot is taken from David's book on rails. As it shown here, we maintain the singular form on to the class names and plural on the table names.
Rails literally understands the singular and plural form of the words you use.

Order orders
Person people

You take a note of the way we write the names:
  • the table names in plural form all lower case letters.
  • the class name in singular form with camel case/capitalized word
Of course, I am sure you have few questions running into your mind:
  1. What if the word does not have proper plural form?
  2. What if I do not want to follow this?
The answers are:
  1. As you can see in the above snapshot, the 'Person' as the class name and 'people' as the table name. And if you do not have proper/matching form for it, or you did not maintain the convention mentioned - you can use a keyword called set_table_name, in the model class where ever you are defining the construct.
  2. You can disable this feature globally with a variable under 'config/environment.rb' of the application. ActiveRecord::Base.pluralize_table_names = false
Well, this is just a convention that help avoid writing/maintaining lot of xml files and connection problems. Let me also tell you that it is not mandatory to have this maintained strictly.
I guessed only the above questions, if you have more questions touch base with me and get them clarified.