diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 13:09:49 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 13:47:10 -0700 |
commit | 99a6f9e60ea55924b44f894a16f8de0162cf2702 (patch) | |
tree | ec97f3ea702a58b18b4a94a58f08ca5bbd512080 /activerecord/examples | |
parent | a9c0c46263dcafcf01944246e31cbe5650ee605e (diff) | |
download | rails-99a6f9e60ea55924b44f894a16f8de0162cf2702.tar.gz rails-99a6f9e60ea55924b44f894a16f8de0162cf2702.tar.bz2 rails-99a6f9e60ea55924b44f894a16f8de0162cf2702.zip |
Add a `foreign_key` option to `references` while creating the table
Rather than having to do:
create_table :posts do |t|
t.references :user
end
add_foreign_key :posts, :users
You can instead do:
create_table :posts do |t|
t.references :user, foreign_key: true
end
Similar to the `index` option, you can also pass a hash. This will be
passed as the options to `add_foreign_key`. e.g.:
create_table :posts do |t|
t.references :user, foreign_key: { primary_key: :other_id }
end
is equivalent to
create_table :posts do |t|
t.references :user
end
add_foreign_key :posts, :users, primary_key: :other_id
Diffstat (limited to 'activerecord/examples')
0 files changed, 0 insertions, 0 deletions