<commit_before>= Foreigner
{<img src="https://secure.travis-ci.org/matthuhiggins/foreigner.png?rvm=1.9.3" />}[http://travis-ci.org/matthuhiggins/foreigner]

Foreigner introduces a few methods to your migrations for adding and removing foreign key constraints. It also dumps foreign keys to schema.rb.

The following adapters are supported:

* mysql2
* postgres
* sqlite (foreign key methods are a no-op)

== Installation

Add the following to your Gemfile:

  gem 'foreigner'

== API Examples

Foreigner adds two methods to migrations.

* add_foreign_key(from_table, to_table, options)
* remove_foreign_key(from_table, options)

(Options are documented in connection_adapters/abstract/schema_definitions.rb):

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')
  
A name can be specified for the foreign key constraint:

  add_foreign_key(:comments, :posts, name: 'comment_article_foreign_key')

== Change Table Methods

Foreigner adds extra methods to change_table.

Add a missing foreign key to comments:

  change_table :comments do |t|
    t.foreign_key :posts, dependent: :delete
  end

Remove an unwanted foreign key:
  
  change_table :comments do |t|
    t.remove_foreign_key :users
  end

== Finding Missing Foreign Keys

Use {Immigrant}[https://github.com/jenseng/immigrant] to generate a migration that includes all missing foreign keys.

== License

Copyright (c) 2012 <NAME>, released under the MIT license<commit_msg>Update README for create_table<commit_after>= Foreigner
{<img src="https://secure.travis-ci.org/matthuhiggins/foreigner.png?rvm=1.9.3" />}[http://travis-ci.org/matthuhiggins/foreigner]

Foreigner introduces a few methods to your migrations for adding and removing foreign key constraints. It also dumps foreign keys to schema.rb.

The following adapters are supported:

* mysql2
* postgres
* sqlite (foreign key methods are a no-op)

== Installation

Add the following to your Gemfile:

  gem 'foreigner'

== API Examples

Foreigner adds two methods to migrations.

* add_foreign_key(from_table, to_table, options)
* remove_foreign_key(from_table, options)

(Options are documented in connection_adapters/abstract/schema_definitions.rb):

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')
  
A name can be specified for the foreign key constraint:

  add_foreign_key(:comments, :posts, name: 'comment_article_foreign_key')

== Change Table Methods

Foreigner adds extra methods to create_table and change_table.

Create a new table with a foreign key:
  
  create_table :products do |t|
    t.string :name
    t.integer :factory_id
    t.foreign_key :factories
  end

Add a missing foreign key to comments:

  change_table :comments do |t|
    t.foreign_key :posts, dependent: :delete
  end

Remove an unwanted foreign key:
  
  change_table :comments do |t|
    t.remove_foreign_key :users
  end

== Finding Missing Foreign Keys

Use {Immigrant}[https://github.com/jenseng/immigrant] to generate a migration that includes all missing foreign keys.

== License

Copyright (c) 2012 <NAME>, released under the MIT license
{'fraction_non_alphanumeric': 0.07890222984562607, 'fraction_numerical': 0.0039206076941926, 'mean_word_length': 4.653739612188366, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2516583', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1209, 'n_words': 445}