<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.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>ronin: Tag activerecord</title>
    <link>http://blogs.divisibleprime.com/ronin/articles/tag/activerecord</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Stuff</description>
    <item>
      <title>Rails Scaffold, ActiveRecord, and table names</title>
      <description>&lt;p&gt;Looks like the Rails scaffolding doesn&amp;#8217;t like it when your model uses a different table name from the default mapping it expects(like when accessing a legacy database model).  &lt;/p&gt;

&lt;p&gt;So if you have a model like so:   &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Thing &amp;lt; ActiveRecord::Base
    set_table_name "some_thing"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then ActiveRecord will be expecting a table called &amp;#8220;some_thing&amp;#8221;, however the scaffolding generator is expecting the default, which is going to be &amp;#8220;things&amp;#8221;(or something like that since I can&amp;#8217;t be bothered actually generating a model called Thing).&lt;/p&gt;

&lt;p&gt;When running your generator you&amp;#8217;re going to end up with an error like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;error  Before updating scaffolding from new DB schema, try creating a table for your model (Thing)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Annoying as this is, you can work around it by temporarily creating the table required by the generator.  Then go ahead and drop it after the generator works.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;create table things ();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;m not sure what longer term effects this causes, and if there is a better way then let me know.  &lt;/p&gt;</description>
      <pubDate>Mon, 21 May 2007 20:36:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:c938c10a-7670-48fd-9f76-3eb6b9cac682</guid>
      <author>Kerry</author>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names</link>
      <category>Rails</category>
      <category>Tech</category>
      <category>Ruby</category>
      <category>ruby</category>
      <category>rails</category>
      <category>activerecord</category>
      <trackback:ping>http://blogs.divisibleprime.com/ronin/articles/trackback/870</trackback:ping>
    </item>
  </channel>
</rss>
