diff options
Diffstat (limited to 'railties/doc/guides/html/active_record_basics.html')
-rw-r--r-- | railties/doc/guides/html/active_record_basics.html | 127 |
1 files changed, 4 insertions, 123 deletions
diff --git a/railties/doc/guides/html/active_record_basics.html b/railties/doc/guides/html/active_record_basics.html index 7ec77781ce..6dad70a46f 100644 --- a/railties/doc/guides/html/active_record_basics.html +++ b/railties/doc/guides/html/active_record_basics.html @@ -303,129 +303,10 @@ 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="tableblock">
-<table rules="all"
-frame="hsides"
-cellspacing="0" cellpadding="4">
-<col width="285" />
-<col width="902" />
-<thead>
- <tr>
- <th align="left">
- Attribute
- </th>
- <th align="left">
- Purpose
- </th>
- </tr>
-</thead>
-<tbody valign="top">
- <tr>
- <td align="left">
- created_at / created_on
- </td>
- <td align="left">
- Rails stores the current date & time to this field when creating the record.
- </td>
- </tr>
- <tr>
- <td align="left">
- updated_at / updated_on
- </td>
- <td align="left">
- Rails stores the current date & time to this field when updating the record.
- </td>
- </tr>
- <tr>
- <td align="left">
- lock_version
- </td>
- <td align="left">
- Adds optimistic locking to a model <a href="http://api.rubyonrails.com/classes/ActiveRecord/Locking.html">more about optimistic locking</a>.
- </td>
- </tr>
- <tr>
- <td align="left">
- type
- </td>
- <td align="left">
- Specifies that the model uses Single Table Inheritance <a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html">more about STI</a>.
- </td>
- </tr>
- <tr>
- <td align="left">
- id
- </td>
- <td align="left">
- All models require an id. the default is name is "id" but can be changed using the "set_primary_key" or "primary_key" methods.
- </td>
- </tr>
- <tr>
- <td align="left">
- <em>table_name</em>\_count
- </td>
- <td align="left">
- Can be used to caches the number of belonging objects on the associated class.
- </td>
- </tr>
-</tbody>
-</table>
-</div>
-<div class="paragraph"><p>By default rails assumes all tables will use “id” as their primary key to identify each record. Though fortunately you won’t have explicitly declare this, Rails will automatically create that field unless you tell it not to.</p></div>
-<div class="paragraph"><p>For example suppose you created a database table called cars:</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>mysql<span style="color: #990000">></span> <span style="font-weight: bold"><span style="color: #0000FF">CREATE</span></span> <span style="font-weight: bold"><span style="color: #0000FF">TABLE</span></span> cars <span style="color: #990000">(</span>
- id <span style="color: #009900">INT</span><span style="color: #990000">,</span>
- color <span style="color: #009900">VARCHAR</span><span style="color: #990000">(</span><span style="color: #993399">100</span><span style="color: #990000">),</span>
- doors <span style="color: #009900">INT</span><span style="color: #990000">,</span>
- horses <span style="color: #009900">INT</span><span style="color: #990000">,</span>
- model <span style="color: #009900">VARCHAR</span><span style="color: #990000">(</span><span style="color: #993399">100</span><span style="color: #990000">)</span>
- <span style="color: #990000">);</span></tt></pre></div></div>
-<div class="paragraph"><p>Now you created a class named Car, which is to represent an instance of a record from your table.</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> Car
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>As you might expect without defining the explicit mappings between your class and the table it is impossible for Rails or any other program to correctly map those relationships.</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="color: #990000">>></span> c <span style="color: #990000">=</span> Car<span style="color: #990000">.</span>new
-<span style="color: #990000">=></span> <span style="font-style: italic"><span style="color: #9A1900">#<Class:0x11e1e90></span></span>
-<span style="color: #990000">>></span> c<span style="color: #990000">.</span>doors
-NoMethodError<span style="color: #990000">:</span> undefined method `doors' <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="font-style: italic"><span style="color: #9A1900">#<Class:0x11e1e90></span></span>
- from <span style="color: #990000">(</span>irb<span style="color: #990000">):</span><span style="color: #993399">2</span></tt></pre></div></div>
-<div class="paragraph"><p>Now you could define a door methods to write and read data to and from the database. In a nutshell this is what ActiveRecord does. According to the Rails API:
-“Active Record objects don‘t specify their attributes directly, but rather infer them from the table definition with which they‘re linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.”
-Lets try our Car class again, this time inheriting from ActiveRecord.</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> Car <span style="color: #990000"><</span> ActiveRecord<span style="color: #990000">::</span>Base
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Now if we try to access an attribute of the table ActiveRecord automatically handles the mappings for us, as you can see in the following example.</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="color: #990000">>></span> c <span style="color: #990000">=</span> Car<span style="color: #990000">.</span>new
-<span style="color: #990000">=></span> <span style="font-style: italic"><span style="color: #9A1900">#<Car id: nil, doors: nil, color: nil, horses: nil, model: nil></span></span>
-<span style="color: #990000">>></span> c<span style="color: #990000">.</span>doors
-<span style="color: #990000">=></span> <span style="font-weight: bold"><span style="color: #0000FF">nil</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Rails further extends this model by giving each ActiveRecord a way of describing the variety of ways records are associated with one another. We will touch on some of these associations later in the guide but I encourage readers who are interested to read the guide to ActiveRecord associations for an in-depth explanation of the variety of ways rails can model associations.
-- Associations between objects controlled by meta-programming macros.</p></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 & Common Conventions</h2>
<div class="sectionbody">
|