I do not possess a Rails atmosphere setup which is really quite difficult to find a fast answer for, so I'll request professionals.

When Rails produces a table according to your "model" you have setup, does Rails produce a table that mirrors this model exactly, or will it include more fields towards the table to assist it work its miracle? If that's the case, the other fields will it add and why? Possibly you can cut and paste the table structure, or just point me to some doc or tutorial section that addresses this.

If you are creating a brand-new application, together with a new database, you'll be able to build the entire back finish with migrations. Running

ruby script/generate model User name:string

produces both a person.rb apply for the model along with a migration:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :name


  def self.down
    drop_table :users

You can observe that automatically the generate script adds "timestamps" for (produced and last up-to-date) and they are handled instantly if permitted to stay present.

Not visible, but important, is the fact that an additional column, "id", is produced to become the only primary key. It isn't complusory, though - you are able to specify your personal primary type in the model, that is helpful if you are using a legacy schema. Presuming you continue id because the key, then Rails uses whatever RDBMS-specific features are for sale to key values.

In ActiveRecord, models are produced from database tables, not the other way round.

You may even wish to consider Migrations, the industry method of explaining and creating the database from Ruby code. However, the migration isn't associated with the model the model continues to be produced at runtime in line with the form of the database.

You will find screencasts associated with ActiveRecord and Migrations around the Rails site: http://www.rubyonrails.org/screencasts

HereIs the official documentation for ActiveRecord. It concurs with Kaira. You may have seen whether different access method or perhaps a migration (which alters the tables and therefore the model)

I've had just a little experience moving legacy databases into Rails and being able to access Rails databases from outdoors scripts. That seems like what you are attempting to do. My experience is within Rails databases built on the top of MySQL, so that your mileage can vary.

The main one hidden area is easily the most apparent --- the "id" area (an integer) that Rails uses since it's default primary key. Unless of course you specify otherwise, each model in Rails comes with an "id" area that's a distinctive, incremented integer primary key. This "id" area can look instantly in almost any model produced within Rails via a migration, unless of course you know Rails to avoid so (by indicating another area to become the main key). If you use Rails databases from outdoors Rails itself, you ought to be careful relating to this value.

The "id" area is really a key area of the Rails miracle since it is accustomed to define Rails' associations. Say you relate two tables together --- Group and Person. The Audience model may have an "id" area, and also the Person model must have both its very own "id" area along with a "group_id" area for that relationship. The worthiness in "group_id" will refer to the initial id from the connected Group. For those who have built your models in ways that follows individuals conventions of Rails, you are able to make the most of Rails' associations by stating that the audience model "has_many :people" which the individual model "goes_to :group".

Rails migrations also, automatically, wish to add "produced_at" and "up-to-date_at" fields (the so-known as "timestamps"), that are datetime fields. Automatically, these make use of the "miracle" within the database --- not in Rails itself --- to instantly update each time a record is produced or modified. I do not think these posts will trip you up, because they must be taken proper care of in the database level, not by any special Rails miracle.