aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides
diff options
context:
space:
mode:
authorCassioMarques <cassiommc@gmail.com>2009-01-31 14:45:35 -0200
committerCassioMarques <cassiommc@gmail.com>2009-01-31 15:12:49 -0200
commit8e98b43db0d8defdb01ff5fef4f34846d1cdb50b (patch)
tree1b12848bdab051df197a5cf7f0eb4a6918a2f5f5 /railties/doc/guides
parentcbf4bef492eb9e65e51019924e19346b1aba07ad (diff)
downloadrails-8e98b43db0d8defdb01ff5fef4f34846d1cdb50b.tar.gz
rails-8e98b43db0d8defdb01ff5fef4f34846d1cdb50b.tar.bz2
rails-8e98b43db0d8defdb01ff5fef4f34846d1cdb50b.zip
Getting rid of some of the pre-existent content in the AR basics guide, adding new stuff to it.
Diffstat (limited to 'railties/doc/guides')
-rw-r--r--railties/doc/guides/html/active_record_basics.html178
-rw-r--r--railties/doc/guides/html/form_helpers.html6
-rw-r--r--railties/doc/guides/html/security.html2
-rw-r--r--railties/doc/guides/source/active_record_basics.txt101
4 files changed, 127 insertions, 160 deletions
diff --git a/railties/doc/guides/html/active_record_basics.html b/railties/doc/guides/html/active_record_basics.html
index 6dad70a46f..f99d57faac 100644
--- a/railties/doc/guides/html/active_record_basics.html
+++ b/railties/doc/guides/html/active_record_basics.html
@@ -43,9 +43,6 @@
<a href="#_active_record_inside_the_mvc_model">Active Record inside the MVC model</a>
</li>
<li>
- <a href="#_creating_activerecord_models">Creating ActiveRecord models</a>
- </li>
- <li>
<a href="#_convention_over_configuration_in_activerecord">Convention over Configuration in ActiveRecord</a>
<ul>
@@ -56,22 +53,16 @@
</ul>
</li>
<li>
- <a href="#_philosophical_approaches_amp_common_conventions">Philosophical Approaches &amp; Common Conventions</a>
- </li>
- <li>
- <a href="#_activerecord_magic">ActiveRecord Magic</a>
- </li>
- <li>
- <a href="#_how_activerecord_maps_your_database">How ActiveRecord Maps your Database.</a>
+ <a href="#_creating_activerecord_models">Creating ActiveRecord models</a>
</li>
<li>
- <a href="#_growing_your_database_relationships_naturally">Growing Your Database Relationships Naturally</a>
+ <a href="#_overriding_the_naming_conventions">Overriding the naming conventions</a>
</li>
<li>
- <a href="#_attributes">Attributes</a>
+ <a href="#_validations">Validations</a>
</li>
<li>
- <a href="#_validations_amp_callbacks">Validations &amp; Callbacks</a>
+ <a href="#_callbacks">Callbacks</a>
</li>
</ol>
</div>
@@ -179,43 +170,23 @@ Perform database operations in an object-oriented fashion.
<div class="sectionbody">
<div class="paragraph"><p>Active Record plays the role of model inside the MVC structure followed by Rails applications. Since model objects should encapsulate both state and logic of your applications, it&#8217;s ActiveRecord responsability to deliver you the easiest possible way to recover this data from the database.</p></div>
</div>
-<h2 id="_creating_activerecord_models">5. Creating ActiveRecord models</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>It&#8217;s very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you&#8217;re good to go:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 2.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Product <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>This will create a <tt>Product</tt> model, mapped to a <strong>products</strong> table at the database. By doing this you&#8217;ll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the <strong>products</strong> table was created using a SQL sentence like:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 2.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">CREATE</span></span> <span style="font-weight: bold"><span style="color: #0000FF">TABLE</span></span> products <span style="color: #990000">(</span>
- id <span style="color: #009900">int</span><span style="color: #990000">(</span><span style="color: #993399">11</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">NOT</span></span> <span style="font-weight: bold"><span style="color: #0000FF">NULL</span></span> <span style="font-weight: bold"><span style="color: #0000FF">auto_increment</span></span><span style="color: #990000">,</span>
- name <span style="color: #009900">varchar</span><span style="color: #990000">(</span><span style="color: #993399">255</span><span style="color: #990000">),</span>
- <span style="font-weight: bold"><span style="color: #0000FF">PRIMARY</span></span> <span style="font-weight: bold"><span style="color: #0000FF">KEY</span></span> <span style="color: #990000">(</span>id<span style="color: #990000">)</span>
-<span style="color: #990000">);</span></tt></pre></div></div>
-<div class="paragraph"><p>Following the table schema above, you would be able to write code like the following:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 2.9
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt>p <span style="color: #990000">=</span> Product<span style="color: #990000">.</span>new
-p<span style="color: #990000">.</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"Some Book"</span>
-puts p<span style="color: #990000">.</span>name <span style="font-style: italic"><span style="color: #9A1900"># "Some Book"</span></span></tt></pre></div></div>
-</div>
-<h2 id="_convention_over_configuration_in_activerecord">6. Convention over Configuration in ActiveRecord</h2>
+<h2 id="_convention_over_configuration_in_activerecord">5. Convention over Configuration in ActiveRecord</h2>
<div class="sectionbody">
<div class="paragraph"><p>When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particulary true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you&#8217;ll need to write very little configuration (in some case no configuration at all) when creating ActiveRecord models. The idea is that if you configure your applications in the very same way most of the times then this should be the default way. In this cases, explicity configuration would be needed only in those cases where you can&#8217;t follow the conventions for any reason.</p></div>
-<h3 id="_naming_conventions">6.1. Naming Conventions</h3>
+<h3 id="_naming_conventions">5.1. Naming Conventions</h3>
<div class="paragraph"><p>By default, ActiveRecord uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class <tt>Book</tt>, you should have a database table called <strong>books</strong>. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples:</p></div>
-<div class="paragraph"><p>Database Table - Plural with underscores separating words i.e. (book_clubs)
-Model Class - Singular with the first letter of each word capitalized i.e. (BookClub)</p></div>
+<div class="ulist"><ul>
+<li>
+<p>
+Database Table - Plural with underscores separating words i.e. (book_clubs)
+</p>
+</li>
+<li>
+<p>
+Model Class - Singular with the first letter of each word capitalized i.e. (BookClub)
+</p>
+</li>
+</ul></div>
<div class="tableblock">
<table rules="all"
width="60%"
@@ -253,7 +224,7 @@ cellspacing="0" cellpadding="4">
</tbody>
</table>
</div>
-<h3 id="_schema_conventions">6.2. Schema Conventions</h3>
+<h3 id="_schema_conventions">5.2. Schema Conventions</h3>
<div class="paragraph"><p>ActiveRecord uses naming conventions for the columns in database tables, depending on the purpose of these columns.</p></div>
<div class="ulist"><ul>
<li>
@@ -303,73 +274,66 @@ cellspacing="0" cellpadding="4">
<td class="content">While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.</td>
</tr></table>
</div>
-<div class="literalblock">
-<div class="content">
-<pre><tt>== STOPED HERE</tt></pre>
-</div></div>
-</div>
-<h2 id="_philosophical_approaches_amp_common_conventions">7. Philosophical Approaches &amp; Common Conventions</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Rails has a reputation of being a zero-config framework which means that it aims to get you off the ground with as little pre-flight checking as possible. This speed benefit is achieved by following “Convention over Configuration”, which is to say that if you agree to live with the defaults then you benefit from a the inherent speed-boost. As Courtneay Gasking put it to me once “You don’t want to off-road on Rails”. ActiveRecord is no different, while it’s possible to override or subvert any of the conventions of AR, unless you have a good reason for doing so you will probably be happy with the defaults. The following is a list of the common conventions of ActiveRecord</p></div>
-</div>
-<h2 id="_activerecord_magic">8. ActiveRecord Magic</h2>
-<div class="sectionbody">
-<div class="ulist"><ul>
-<li>
-<p>
-timestamps
-</p>
-</li>
-<li>
-<p>
-updates
-</p>
-</li>
-</ul></div>
</div>
-<h2 id="_how_activerecord_maps_your_database">9. How ActiveRecord Maps your Database.</h2>
+<h2 id="_creating_activerecord_models">6. Creating ActiveRecord models</h2>
<div class="sectionbody">
-<div class="ulist"><ul>
-<li>
-<p>
-sensible defaults
-</p>
-</li>
-<li>
-<p>
-overriding conventions
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>It&#8217;s very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you&#8217;re good to go:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Product <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>This will create a <tt>Product</tt> model, mapped to a <strong>products</strong> table at the database. By doing this you&#8217;ll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the <strong>products</strong> table was created using a SQL sentence like:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">CREATE</span></span> <span style="font-weight: bold"><span style="color: #0000FF">TABLE</span></span> products <span style="color: #990000">(</span>
+ id <span style="color: #009900">int</span><span style="color: #990000">(</span><span style="color: #993399">11</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">NOT</span></span> <span style="font-weight: bold"><span style="color: #0000FF">NULL</span></span> <span style="font-weight: bold"><span style="color: #0000FF">auto_increment</span></span><span style="color: #990000">,</span>
+ name <span style="color: #009900">varchar</span><span style="color: #990000">(</span><span style="color: #993399">255</span><span style="color: #990000">),</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">PRIMARY</span></span> <span style="font-weight: bold"><span style="color: #0000FF">KEY</span></span> <span style="color: #990000">(</span>id<span style="color: #990000">)</span>
+<span style="color: #990000">);</span></tt></pre></div></div>
+<div class="paragraph"><p>Following the table schema above, you would be able to write code like the following:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt>p <span style="color: #990000">=</span> Product<span style="color: #990000">.</span>new
+p<span style="color: #990000">.</span>name <span style="color: #990000">=</span> <span style="color: #FF0000">"Some Book"</span>
+puts p<span style="color: #990000">.</span>name <span style="font-style: italic"><span style="color: #9A1900"># "Some Book"</span></span></tt></pre></div></div>
</div>
-<h2 id="_growing_your_database_relationships_naturally">10. Growing Your Database Relationships Naturally</h2>
+<h2 id="_overriding_the_naming_conventions">7. Overriding the naming conventions</h2>
<div class="sectionbody">
+<div class="paragraph"><p>What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.</p></div>
+<div class="paragraph"><p>You can use the <tt>ActiveRecord::Base.set_table_name</tt> method to specify the table name that should be used:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Product <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
+ set_table_name <span style="color: #FF0000">"PRODUCT"</span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>It&#8217;s also possible to override the column that should be used as the table&#8217;s primary key. Use the <tt>ActiveRecord::Base.set_primary_key</tt> method for that:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Product <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
+ set_primary_key <span style="color: #FF0000">"product_id"</span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
</div>
-<h2 id="_attributes">11. Attributes</h2>
+<h2 id="_validations">8. Validations</h2>
<div class="sectionbody">
-<div class="ulist"><ul>
-<li>
-<p>
-attribute accessor method. How to override them?
-</p>
-</li>
-<li>
-<p>
-attribute?
-</p>
-</li>
-<li>
-<p>
-dirty records
- -
-== ActiveRecord handling the CRUD of your Rails application - Understanding the life-cycle of an ActiveRecord
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>ActiveRecord gives the hability to validate the state of your models before they get recorded into the database. There are several methods that you can use to hook into the lifecycle of your models and validate that an attribute value is not empty or follow a specific format and so on. You can learn more about validations in the <a href="http://guides.rails.info/activerecord_validations_callbacks.html#_overview_of_activerecord_validation">Active Record Validations and Callbacks guide</a>.</p></div>
</div>
-<h2 id="_validations_amp_callbacks">12. Validations &amp; Callbacks</h2>
+<h2 id="_callbacks">9. Callbacks</h2>
<div class="sectionbody">
-<div class="paragraph"><p>see the Validations &amp; Callbacks guide for more info.</p></div>
+<div class="paragraph"><p>ActiveRecord callbacks allow you to attach code to certain events in the lifecycle of your models. This way you can add behaviour to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on. You can learn more about callbacks in the <a href="http://guides.rails.info/activerecord_validations_callbacks.html#_callbacks">Active Record Validations and Callbacks guide</a>.</p></div>
</div>
</div>
diff --git a/railties/doc/guides/html/form_helpers.html b/railties/doc/guides/html/form_helpers.html
index 2693f29a9a..d5e571ae31 100644
--- a/railties/doc/guides/html/form_helpers.html
+++ b/railties/doc/guides/html/form_helpers.html
@@ -197,7 +197,7 @@ Find out where to look for complex forms
</div>
<h3 id="_a_generic_search_form">1.1. A Generic search form</h3>
<div class="paragraph"><p>Probably the most minimal form often seen on the web is a search form with a single text input for search terms. This form consists of:</p></div>
-<div class="olist arabic"><ol class="arabic">
+<div class="olist"><ol>
<li>
<p>
a form element with "GET" method,
@@ -420,7 +420,7 @@ end</tt></pre>
&lt;% end %&gt;</tt></pre>
</div></div>
<div class="paragraph"><p>There are a few things to note here:</p></div>
-<div class="olist arabic"><ol class="arabic">
+<div class="olist"><ol>
<li>
<p>
<tt>:article</tt> is the name of the model and <tt>@article</tt> is the actual object being edited.
@@ -662,7 +662,7 @@ output:
<h2 id="_using_date_and_time_form_helpers">4. Using Date and Time Form Helpers</h2>
<div class="sectionbody">
<div class="paragraph"><p>The date and time helpers differ from all the other form helpers in two important respects:</p></div>
-<div class="olist arabic"><ol class="arabic">
+<div class="olist"><ol>
<li>
<p>
Dates and times are not representable by a single input element. Instead you have several, one for each component (year, month, day etc.) and so there is no single value in your <tt>params</tt> hash with your date or time.
diff --git a/railties/doc/guides/html/security.html b/railties/doc/guides/html/security.html
index 371decda64..4751e9f92b 100644
--- a/railties/doc/guides/html/security.html
+++ b/railties/doc/guides/html/security.html
@@ -326,7 +326,7 @@ The user has his credit back.
</div>
</div>
<div class="paragraph"><p>This attack focuses on fixing a user&#8217;s session id known to the attacker, and forcing the user&#8217;s browser into using this id. It is therefore not necessary for the attacker to steal the session id afterwards. Here is how this attack works:</p></div>
-<div class="olist arabic"><ol class="arabic">
+<div class="olist"><ol>
<li>
<p>
The attacker creates a valid session id: He loads the login page of the web application where he wants to fix the session, and takes the session id in the cookie from the response (see number 1 and 2 in the image).
diff --git a/railties/doc/guides/source/active_record_basics.txt b/railties/doc/guides/source/active_record_basics.txt
index dd62b9a948..2336e162dc 100644
--- a/railties/doc/guides/source/active_record_basics.txt
+++ b/railties/doc/guides/source/active_record_basics.txt
@@ -44,35 +44,6 @@ It's easy to see that the Rails Active Record implementation goes way beyond the
Active Record plays the role of model inside the MVC structure followed by Rails applications. Since model objects should encapsulate both state and logic of your applications, it's ActiveRecord responsability to deliver you the easiest possible way to recover this data from the database.
-== Creating ActiveRecord models
-
-It's very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you're good to go:
-
-[source, ruby]
-------------------------------------------------------------------
-class Product < ActiveRecord::Base; end
-------------------------------------------------------------------
-
-This will create a +Product+ model, mapped to a *products* table at the database. By doing this you'll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the *products* table was created using a SQL sentence like:
-
-[source, sql]
-------------------------------------------------------------------
-CREATE TABLE products (
- id int(11) NOT NULL auto_increment,
- name varchar(255),
- PRIMARY KEY (id)
-);
-------------------------------------------------------------------
-
-Following the table schema above, you would be able to write code like the following:
-
-[source, ruby]
-------------------------------------------------------------------
-p = Product.new
-p.name = "Some Book"
-puts p.name # "Some Book"
-------------------------------------------------------------------
-
== Convention over Configuration in ActiveRecord
When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particulary true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you'll need to write very little configuration (in some case no configuration at all) when creating ActiveRecord models. The idea is that if you configure your applications in the very same way most of the times then this should be the default way. In this cases, explicity configuration would be needed only in those cases where you can't follow the conventions for any reason.
@@ -81,8 +52,8 @@ When writing applications using other programming languages or frameworks, it ma
By default, ActiveRecord uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class +Book+, you should have a database table called *books*. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples:
-Database Table - Plural with underscores separating words i.e. (book_clubs)
-Model Class - Singular with the first letter of each word capitalized i.e. (BookClub)
+* Database Table - Plural with underscores separating words i.e. (book_clubs)
+* Model Class - Singular with the first letter of each word capitalized i.e. (BookClub)
[width="60%", options="header"]
|==============================
@@ -111,28 +82,60 @@ There are also some optional column names that will create additional features t
NOTE: While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.
- == STOPED HERE
+== Creating ActiveRecord models
+It's very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you're good to go:
-== Philosophical Approaches & Common Conventions
-Rails has a reputation of being a zero-config framework which means that it aims to get you off the ground with as little pre-flight checking as possible. This speed benefit is achieved by following “Convention over Configuration”, which is to say that if you agree to live with the defaults then you benefit from a the inherent speed-boost. As Courtneay Gasking put it to me once “You don’t want to off-road on Rails”. ActiveRecord is no different, while it’s possible to override or subvert any of the conventions of AR, unless you have a good reason for doing so you will probably be happy with the defaults. The following is a list of the common conventions of ActiveRecord
+[source, ruby]
+------------------------------------------------------------------
+class Product < ActiveRecord::Base; end
+------------------------------------------------------------------
+
+This will create a +Product+ model, mapped to a *products* table at the database. By doing this you'll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the *products* table was created using a SQL sentence like:
+
+[source, sql]
+------------------------------------------------------------------
+CREATE TABLE products (
+ id int(11) NOT NULL auto_increment,
+ name varchar(255),
+ PRIMARY KEY (id)
+);
+------------------------------------------------------------------
+
+Following the table schema above, you would be able to write code like the following:
+
+[source, ruby]
+------------------------------------------------------------------
+p = Product.new
+p.name = "Some Book"
+puts p.name # "Some Book"
+------------------------------------------------------------------
+
+== Overriding the naming conventions
+
+What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.
+
+You can use the +ActiveRecord::Base.set_table_name+ method to specify the table name that should be used:
+[source, ruby]
+------------------------------------------------------------------
+class Product < ActiveRecord::Base
+ set_table_name "PRODUCT"
+end
+------------------------------------------------------------------
+
+It's also possible to override the column that should be used as the table's primary key. Use the +ActiveRecord::Base.set_primary_key+ method for that:
+[source, ruby]
+------------------------------------------------------------------
+class Product < ActiveRecord::Base
+ set_primary_key "product_id"
+end
+------------------------------------------------------------------
-== ActiveRecord Magic
- - timestamps
- - updates
+== Validations
-== How ActiveRecord Maps your Database.
-- sensible defaults
-- overriding conventions
+ActiveRecord gives the hability to validate the state of your models before they get recorded into the database. There are several methods that you can use to hook into the lifecycle of your models and validate that an attribute value is not empty or follow a specific format and so on. You can learn more about validations in the http://guides.rails.info/activerecord_validations_callbacks.html#_overview_of_activerecord_validation[Active Record Validations and Callbacks guide].
-== Growing Your Database Relationships Naturally
+== Callbacks
-== Attributes
- - attribute accessor method. How to override them?
- - attribute?
- - dirty records
- -
-== ActiveRecord handling the CRUD of your Rails application - Understanding the life-cycle of an ActiveRecord
+ActiveRecord callbacks allow you to attach code to certain events in the lifecycle of your models. This way you can add behaviour to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on. You can learn more about callbacks in the http://guides.rails.info/activerecord_validations_callbacks.html#_callbacks[Active Record Validations and Callbacks guide].
-== Validations & Callbacks
-see the Validations & Callbacks guide for more info.