<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Spoken: Creating a table with migrations when using has_and_belongs_to_many</title>
    <link>http://spoken.phrasewise.com/articles/2006/03/29/creating-a-table-with-migrations-when-using-has_and_belongs_to_many</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Daniel Berlinger :: helpless :: speechless :: breathless</description>
    <item>
      <title>Creating a table with migrations when using has_and_belongs_to_many</title>
      <description>&lt;p&gt;So Rails has this great facility for controlling the database called migrations. Anyone who has worked with database backed apps for a while knows that one of the issues to be handled is keeping the database in sync with various app revisions&amp;#8230; and when things go wrong&amp;#8230; rolling the database back to the previous version. Rails has built in facilities for this. Nice. A migration contains two methods, an up and a down. Up is called when migrating forward so you build a table by saying something like&lt;/p&gt;

&lt;pre&gt;
    def self.up
        create_table :events do |table|
          table.column :title, :string
          table.column :description, :string
          table.column :place, :string
          table.column :takes_place_on, :datetime
         end
  end
&lt;/pre&gt;

&lt;p&gt;Rails convention adds an id column to this. But what if you wish to build an intermediate join table?&lt;/p&gt;

&lt;p&gt;This will get you going:&lt;/p&gt;

&lt;pre&gt;
create_table :table_name, :id =&gt; false do |table|
 ...
end
&lt;/pre&gt;</description>
      <pubDate>Wed, 29 Mar 2006 20:34:17 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:00e0eb9a-ec03-4b88-9495-a91c2acec886</guid>
      <author>Daniel</author>
      <link>http://spoken.phrasewise.com/articles/2006/03/29/creating-a-table-with-migrations-when-using-has_and_belongs_to_many</link>
      <category>code</category>
      <trackback:ping>http://spoken.phrasewise.com/articles/trackback/200</trackback:ping>
    </item>
  </channel>
</rss>
