CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Fri, 08 Aug 2025 02:15:16 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100206175814
location: https://web.archive.org/web/20100206175814/https://github.com/matthuhiggins/foreigner
server-timing: captures_list;dur=2.316231, exclusion.robots;dur=0.034640, exclusion.robots.policy;dur=0.015251, esindex;dur=0.019470, cdx.remote;dur=35.876468, LoadShardBlock;dur=338.150578, PetaboxLoader3.datanode;dur=64.276488, PetaboxLoader3.resolve;dur=63.822756
x-app-server: wwwb-app214
x-ts: 302
x-tr: 442
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app214; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Fri, 08 Aug 2025 02:15:17 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.7.61
x-archive-orig-date: Sat, 06 Feb 2010 17:58:14 GMT
x-archive-orig-connection: close
x-archive-orig-status: 200 OK
x-archive-orig-etag: "d6679af0bed0d91ca8dab165640173ef"
x-archive-orig-x-runtime: 96ms
x-archive-orig-content-length: 27297
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 06 Feb 2010 17:58:14 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Thu, 17 Sep 2009 03:35:17 GMT", ; rel="prev memento"; datetime="Wed, 06 Jan 2010 13:16:11 GMT", ; rel="memento"; datetime="Sat, 06 Feb 2010 17:58:14 GMT", ; rel="next memento"; datetime="Wed, 10 Mar 2010 17:17:57 GMT", ; rel="last memento"; datetime="Sun, 15 Jun 2025 05:05:09 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 51_14_20100206133815_crawl102-c/51_14_20100206175723_crawl101.arc.gz
server-timing: captures_list;dur=0.532391, exclusion.robots;dur=0.018816, exclusion.robots.policy;dur=0.008363, esindex;dur=0.011206, cdx.remote;dur=6.517364, LoadShardBlock;dur=193.258870, PetaboxLoader3.datanode;dur=90.960193, PetaboxLoader3.resolve;dur=227.924408, load_resource;dur=251.026921
x-app-server: wwwb-app214
x-ts: 200
x-tr: 511
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
matthuhiggins's foreigner at master - GitHub
This service is courtesy of Pledgie.
matthuhiggins / foreigner
- Source
- Commits
- Network (13)
- Issues (3)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
Branches (1)
- master ✓
- Tags (0)
Sending Request…
Enable Donations
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
Foreign keys for Rails migrations — Read more

Matthew Higgins (author)
Wed Jan 20 12:22:15 -0800 2010
name | age | message | |
---|---|---|---|
![]() |
MIT-LICENSE | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
![]() |
README | Wed Jan 20 12:22:15 -0800 2010 | Fix syntax error in README. Issue 17 (Thanks li... [Matthew Higgins] |
![]() |
Rakefile | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
![]() |
foreigner.gemspec | Fri Dec 25 11:41:49 -0800 2009 | Update gem spec because new deprecations added [Matthew Higgins] |
![]() |
init.rb | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
![]() |
install.rb | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
![]() |
lib/ | Mon Jan 11 15:21:10 -0800 2010 | Add support for active_record.table_name_prefix... [Matthew Higgins] |
![]() |
tasks/ | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
![]() |
test/ | Sun Sep 06 19:28:54 -0700 2009 | Don't need to mess with the load path - the Rak... [Matthew Higgins] |
![]() |
uninstall.rb | Wed Apr 15 22:51:24 -0700 2009 | First! [Matthew Higgins] |
README
Foreigner ========= Rails does not come with methods to add foreign keys. Foreigner introduces a few methods to your migrations for adding and removing foreign key constraints. Since each adapter implements the API, migrations using Foreigner will continue to work on databases that do not support foreign keys, such as sqlite3. Installation ------------ Install as a plugin: ruby script/plugin install git://github.com/matthuhiggins/foreigner.git Install as a gem by adding the following to environment.rb: config.gem "matthuhiggins-foreigner", :lib => "foreigner", :source => "https://gemcutter.org" API --- An adapter implementing the Foreigner API implements three methods. (Options are documented in connection_adapters/abstract/schema_definitions.rb): add_foreign_key(from_table, to_table, options) remove_foreign_key(from_table, options) foreign_keys(table_name) Example ------- The most common use of foreign keys is to reference a table that a model belongs to. For example, given the following model: class Comment < ActiveRecord::Base belongs_to :post end class Post < ActiveRecord::Base has_many :comments, :dependent => :delete_all end You should add a foreign key in your migration: add_foreign_key(:comments, :posts) The :dependent option can be moved from the has_many definition to the foreign key: add_foreign_key(:comments, :posts, :dependent => :delete) If the column is named article_id instead of post_id, use the :column option: add_foreign_key(:comments, :posts, :column => 'article_id') Lastly, a name can be specified for the foreign key constraint: add_foreign_key(:comments, :posts, :name => 'comment_article_foreign_key') Create/Change Table Shorthand ----------------------------- Foreigner adds extra behavior to change_table, which lets you define foreign keys using shorthand. Add a missing foreign key to comments: change_table :comments do |t| t.foreign_key :posts, :dependent => :delete end t.foreign_key accepts the same options as add_foreign_key. Additional t.references option ------------------------------ Foreigner extends table.references with the :foreign_key option. Pass true, and the default foreign key options are used: change_table :comments do |t| t.references :post, :foreign_key => true end An options hash can also be passed. It accepts the same options as add_foreign_key: change_table :comments do |t| t.references :author, :foreign_key => {:dependent => :destroy} end By default, t.references will not generate a foreign key. schema.rb --------- Similar to indexes, the foreign keys in your database are automatically dumped to schema.rb. This allows you to use foreign keys without fighting Rails! Copyright (c) 2009 Matthew Higgins, released under the MIT license