active_record_foreign_keys icon indicating copy to clipboard operation
active_record_foreign_keys copied to clipboard

Foreign keys support for ActiveRecord

= active_record_foreign_keys

Foreign keys support for ActiveRecord.

THE PROJECT IS DEPRECATED. Please, use https://github.com/lomba/schema_plus

== Install

Rails::Initializer.run do |config| ... config.gem "active_record_foreign_keys", :source => "http://gemcutter.org" ... end

$ rake gems:install

== Usage

def self.up # create reference table create_table :users do |t| end

# create referencing table
create_table :a_examples do |t|
  t.references :user, :foreign_key => true
end

# or
create_table :b_examples do |t|
  t.references :user, :foreign_key => { :on_update => :cascade, :on_delete => :restrict }
end

# or
create_table :c_examples do |t|
end

add_foreign_key :c_examples, :user_id, :users, :id, :on_update => :no_action, :on_delete => :set_null

# or change existing table
change_table :d_examples do |t|
  t.references :user, :foreign_key => true
end

end

def self.down # remove constraint remove_foreign_key :examples, :user_id, :users, :id end

== Copyright

Copyright (c) 2009 Anton Ageev. See LICENSE for details.