This repository has been archived by the owner. It is now read-only.
Foreign keys support for ActiveRecord
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
rails
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
active_record_foreign_keys.gemspec

README.rdoc

active_record_foreign_keys

Foreign keys support for ActiveRecord.

THE PROJECT IS DEPRECATED. Please, use 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 © 2009 Anton Ageev. See LICENSE for details.