This project is archived and is in readonly mode.

#640 ✓resolved
F2Andy

Add magic encoding comment to generated files

Reported by F2Andy | July 17th, 2008 @ 11:21 AM | in 2.x

The references column type generates a column with _id appended to the name, so for example:

generate skaffold comment author:string body:text post:references

... will create a column called post_id of type integer. However, the fixture generated uses the column without the _id

This is with ails 2.1.0 and Ruby 1.8.6.

Recreating the bug

Create new project

rake database create all

generate skaffold post title:string body:text

generate skaffold comment author:string body:text post:references

migrate to current version

test

The error reported (with MySQL):

test_truth(CommentTest): ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column 'post' in 'field list': INSERT INTO `comments` (`updated_at`, `body`, `post`, `author`, `id`, `created_at`) VALUES ('2008-07-17 09:53:38', 'MyText', NULL, 'MyString', 996332877, '2008-07-17 09:53:38')

The migration generated

class CreateComments < ActiveRecord::Migration
  def self.up
    create_table :comments do |t|
      t.string :author
      t.text :body
      t.references :post

      t.timestamps
    end
  end

  def self.down
    drop_table :comments
  end
end

The fixture file generated

# Read about fixtures at http://ar.rubyonrails.org/classe...

one:
  author: MyString
  body: MyText
  post: 

two:
  author: MyString
  body: MyText
  post: 

The workaround

Add _id to the fixtures file in the right places!

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages