views:

30

answers:

1

I'm running activerecord 3.0.0beta. I know you can create columns with foreign keys like

create_table "my_things" do |t|
  t.reference "other_thing_id"
end

but I forgot and just made it a plain integer. Now, I've added a migration like

execute("alter table my_things add constraint fk_other_thing foreign key (other_thing_id) references other_things(id)")

That worked fine, but I don't see anything equivalent appear in schema.rb (I was hoping for t.reference), so if I did a schema load, I wouldn't get my constraint. What's the best way to fix that?

+1  A: 

You might be interested in foreigner. It helps you create foreign keys in your migrations and also adds them to your schema.rb.

Tomas Markauskas
Cool. I'd seen it but didn't know if it support schema.rb. I'll check it out.
Isaac Cambron