<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Class: ActiveRecord::ConnectionAdapters::Table</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Class</strong></td> <td class="class-name-in-header">ActiveRecord::ConnectionAdapters::Table</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../../files/lib/active_record/connection_adapters/abstract/schema_definitions_rb.html"> lib/active_record/connection_adapters/abstract/schema_definitions.rb </a> <br /> </td> </tr> <tr class="top-aligned-row"> <td><strong>Parent:</strong></td> <td> Object </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> Represents a SQL table in an abstract way for updating a table. Also see <a href="TableDefinition.html">TableDefinition</a> and <a href="SchemaStatements.html#M000155">SchemaStatements#create_table</a> </p> <p> Available transformations are: </p> <pre> change_table :table do |t| t.column t.index t.timestamps t.change t.change_default t.rename t.references t.belongs_to t.string t.text t.integer t.float t.decimal t.datetime t.timestamp t.time t.date t.binary t.boolean t.remove t.remove_references t.remove_belongs_to t.remove_index t.remove_timestamps end </pre> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000243">belongs_to</a> <a href="#M000236">change</a> <a href="#M000237">change_default</a> <a href="#M000233">column</a> <a href="#M000234">index</a> <a href="#M000232">new</a> <a href="#M000242">references</a> <a href="#M000238">remove</a> <a href="#M000245">remove_belongs_to</a> <a href="#M000239">remove_index</a> <a href="#M000244">remove_references</a> <a href="#M000240">remove_timestamps</a> <a href="#M000241">rename</a> <a href="#M000235">timestamps</a> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Class methods</h3> <div id="method-M000232" class="method-detail"> <a name="M000232"></a> <div class="method-heading"> <a href="Table.src/M000232.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000232.html');return false;"> <span class="method-name">new</span><span class="method-args">(table_name, base)</span> </a> </div> <div class="method-description"> </div> </div> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000243" class="method-detail"> <a name="M000243"></a> <div class="method-heading"> <span class="method-name">belongs_to</span><span class="method-args">(*args)</span> </div> <div class="method-description"> <p> Alias for <a href="Table.html#M000242">references</a> </p> </div> </div> <div id="method-M000236" class="method-detail"> <a name="M000236"></a> <div class="method-heading"> <a href="Table.src/M000236.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000236.html');return false;"> <span class="method-name">change</span><span class="method-args">(column_name, type, options = {})</span> </a> </div> <div class="method-description"> <p> Changes the <a href="Table.html#M000233">column</a>‘s definition according to the <a href="Table.html#M000232">new</a> options. See <a href="TableDefinition.html#M000211">TableDefinition#column</a> for details of the options you can use. </p> <h5>Examples</h5> <pre> t.change(:name, :string, :limit => 80) t.change(:description, :text) </pre> </div> </div> <div id="method-M000237" class="method-detail"> <a name="M000237"></a> <div class="method-heading"> <a href="Table.src/M000237.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000237.html');return false;"> <span class="method-name">change_default</span><span class="method-args">(column_name, default)</span> </a> </div> <div class="method-description"> <p> Sets a <a href="Table.html#M000232">new</a> default value for a <a href="Table.html#M000233">column</a>. See <a href="SchemaStatements.html#M000163">SchemaStatements#change_column_default</a> </p> <h5>Examples</h5> <pre> t.change_default(:qualification, 'new') t.change_default(:authorized, 1) </pre> </div> </div> <div id="method-M000233" class="method-detail"> <a name="M000233"></a> <div class="method-heading"> <a href="Table.src/M000233.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000233.html');return false;"> <span class="method-name">column</span><span class="method-args">(column_name, type, options = {})</span> </a> </div> <div class="method-description"> <p> Adds a <a href="Table.html#M000232">new</a> <a href="Table.html#M000233">column</a> to the named table. See <a href="TableDefinition.html#M000211">TableDefinition#column</a> for details of the options you can use. </p> <h5>Example</h5> <h6>Creating a simple <a href="Table.html#M000233">column</a></h6> <pre> t.column(:name, :string) </pre> </div> </div> <div id="method-M000234" class="method-detail"> <a name="M000234"></a> <div class="method-heading"> <a href="Table.src/M000234.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000234.html');return false;"> <span class="method-name">index</span><span class="method-args">(column_name, options = {})</span> </a> </div> <div class="method-description"> <p> Adds a <a href="Table.html#M000232">new</a> <a href="Table.html#M000234">index</a> to the table. <tt>column_name</tt> can be a single Symbol, or an Array of Symbols. See <a href="SchemaStatements.html#M000165">SchemaStatements#add_index</a> </p> <h5>Examples</h5> <h6>Creating a simple <a href="Table.html#M000234">index</a></h6> <pre> t.index(:name) </pre> <h6>Creating a unique <a href="Table.html#M000234">index</a></h6> <pre> t.index([:branch_id, :party_id], :unique => true) </pre> <h6>Creating a named <a href="Table.html#M000234">index</a></h6> <pre> t.index([:branch_id, :party_id], :unique => true, :name => 'by_branch_party') </pre> </div> </div> <div id="method-M000242" class="method-detail"> <a name="M000242"></a> <div class="method-heading"> <a href="Table.src/M000242.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000242.html');return false;"> <span class="method-name">references</span><span class="method-args">(*args)</span> </a> </div> <div class="method-description"> <p> Adds a reference. Optionally adds a <tt>type</tt> <a href="Table.html#M000233">column</a>. <tt><a href="Table.html#M000242">references</a></tt> and <tt><a href="Table.html#M000243">belongs_to</a></tt> are acceptable. </p> <h5>Examples</h5> <pre> t.references(:goat) t.references(:goat, :polymorphic => true) t.belongs_to(:goat) </pre> </div> </div> <div id="method-M000238" class="method-detail"> <a name="M000238"></a> <div class="method-heading"> <a href="Table.src/M000238.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000238.html');return false;"> <span class="method-name">remove</span><span class="method-args">(*column_names)</span> </a> </div> <div class="method-description"> <p> Removes the <a href="Table.html#M000233">column</a>(s) from the table definition. </p> <h5>Examples</h5> <pre> t.remove(:qualification) t.remove(:qualification, :experience) </pre> </div> </div> <div id="method-M000245" class="method-detail"> <a name="M000245"></a> <div class="method-heading"> <span class="method-name">remove_belongs_to</span><span class="method-args">(*args)</span> </div> <div class="method-description"> <p> Alias for <a href="Table.html#M000244">remove_references</a> </p> </div> </div> <div id="method-M000239" class="method-detail"> <a name="M000239"></a> <div class="method-heading"> <a href="Table.src/M000239.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000239.html');return false;"> <span class="method-name">remove_index</span><span class="method-args">(options = {})</span> </a> </div> <div class="method-description"> <p> Removes the given <a href="Table.html#M000234">index</a> from the table. </p> <h5>Examples</h5> <h6>Remove the suppliers_name_index in the suppliers table</h6> <pre> t.remove_index :name </pre> <h6>Remove the <a href="Table.html#M000234">index</a> named accounts_branch_id_index in the accounts table</h6> <pre> t.remove_index :column => :branch_id </pre> <h6>Remove the <a href="Table.html#M000234">index</a> named accounts_branch_id_party_id_index in the accounts table</h6> <pre> t.remove_index :column => [:branch_id, :party_id] </pre> <h6>Remove the <a href="Table.html#M000234">index</a> named by_branch_party in the accounts table</h6> <pre> t.remove_index :name => :by_branch_party </pre> </div> </div> <div id="method-M000244" class="method-detail"> <a name="M000244"></a> <div class="method-heading"> <a href="Table.src/M000244.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000244.html');return false;"> <span class="method-name">remove_references</span><span class="method-args">(*args)</span> </a> </div> <div class="method-description"> <p> Removes a reference. Optionally removes a <tt>type</tt> <a href="Table.html#M000233">column</a>. <tt><a href="Table.html#M000244">remove_references</a></tt> and <tt><a href="Table.html#M000245">remove_belongs_to</a></tt> are acceptable. </p> <h5>Examples</h5> <pre> t.remove_references(:goat) t.remove_references(:goat, :polymorphic => true) t.remove_belongs_to(:goat) </pre> </div> </div> <div id="method-M000240" class="method-detail"> <a name="M000240"></a> <div class="method-heading"> <a href="Table.src/M000240.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000240.html');return false;"> <span class="method-name">remove_timestamps</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Removes the timestamp columns (created_at and updated_at) from the table. </p> <h5>Example</h5> <pre> t.remove_timestamps </pre> </div> </div> <div id="method-M000241" class="method-detail"> <a name="M000241"></a> <div class="method-heading"> <a href="Table.src/M000241.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000241.html');return false;"> <span class="method-name">rename</span><span class="method-args">(column_name, new_column_name)</span> </a> </div> <div class="method-description"> <p> Renames a <a href="Table.html#M000233">column</a>. </p> <h5>Example</h5> <pre> t.rename(:description, :name) </pre> </div> </div> <div id="method-M000235" class="method-detail"> <a name="M000235"></a> <div class="method-heading"> <a href="Table.src/M000235.html" target="Code" class="method-signature" onclick="popupCode('Table.src/M000235.html');return false;"> <span class="method-name">timestamps</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Adds <a href="Table.html#M000235">timestamps</a> (created_at and updated_at) columns to the table. See <a href="SchemaStatements.html#M000172">SchemaStatements#add_timestamps</a> </p> <h5>Example</h5> <pre> t.timestamps </pre> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>