Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Foreign keys support for ActiveRecord

License

Notifications You must be signed in to change notification settings

antage/active_record_foreign_keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 © 2009 Anton Ageev. See LICENSE for details.

About

Foreign keys support for ActiveRecord

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages