Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Can't use :references in add_column

#270

I have a User and an Address model, where User has_one :address. When creating the Address mode, I am planning for a polymorphic association for another model that also has_one :address. I need to use :references in a migration using add_column, just as I would using create_table.

I expected the following to work:

add_column :users, :addressable, :references, :polymorphic => true

here is the error:

== 20080526144501 CreateAddresses: migrating ==================================

-- create_table(:addresses)

-> 0.0040s

-- add_column(:users, :addressable, :references, {:polymorphic=>true})

rake aborted!

Workaround (reversed from schema.rb):

add_column :users, :addressable_id, :integer, :limit => 11

add_column :users, :addressable_type, :string

Thanks,

Mark

Reported by Mark A. Richman · May 28th, 2008 @ 07:40 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Darragh Curran
    Darragh Curran
    • Tag cleared.

    What you think about change_table?

    change_table :users do |t|

    t.references :addressable, :polymorphic => true

    end

    calling add column with expectation of having two columns sounds wrong to me - whereas using change table you get the same syntax you would have with create table

    July 3rd, 2008 @ 11:03 AM

  2. josh
    josh
    • State changed from new to wontfix

    October 5th, 2008 @ 03:18 PM