matthuhiggins-foreigner 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -83,7 +83,7 @@ foreign key options are used:
83
83
  An options hash can also be passed. It accepts the same options as add_foreign_key:
84
84
 
85
85
  change_table :comments do |t|
86
- t.references :author, :foreign_key => {:dependent => :destroy}
86
+ t.references :author, :foreign_key => {:dependent => :restrict}
87
87
  end
88
88
 
89
89
  By default, t.references will not generate a foreign key.
@@ -30,11 +30,11 @@ module Foreigner
30
30
  fk_info.map do |row|
31
31
  options = {:column => row['column'], :name => row['name'], :primary_key => row['primary_key']}
32
32
 
33
- if create_table_info =~ /CONSTRAINT #{quote_column_name(row['name'])} FOREIGN KEY .* REFERENCES .* ON DELETE (CASCADE|SET NULL)/
34
- if $1 == 'CASCADE'
35
- options[:dependent] = :delete
36
- elsif $1 == 'SET NULL'
37
- options[:dependent] = :nullify
33
+ if create_table_info =~ /CONSTRAINT #{quote_column_name(row['name'])} FOREIGN KEY .* REFERENCES .* ON DELETE (CASCADE|SET NULL|RESTRICT)/
34
+ options[:dependent] = case $1
35
+ when 'CASCADE' then :delete
36
+ when 'SET NULL' then :nullify
37
+ when 'RESTRICT' then :restrict
38
38
  end
39
39
  end
40
40
  ForeignKeyDefinition.new(table_name, row['to_table'], options)
@@ -35,11 +35,12 @@ module Foreigner
35
35
  fk_info.map do |row|
36
36
  options = {:column => row['column'], :name => row['name'], :primary_key => row['primary_key']}
37
37
 
38
- if row['dependency'] == 'CASCADE'
39
- options[:dependent] = :delete
40
- elsif row['dependency'] == 'SET NULL'
41
- options[:dependent] = :nullify
38
+ options[:dependent] = case row['dependency']
39
+ when 'CASCADE' then :delete
40
+ when 'SET NULL' then :nullify
41
+ when 'RESTRICT' then :restrict
42
42
  end
43
+
43
44
  ForeignKeyDefinition.new(table_name, row['to_table'], options)
44
45
  end
45
46
  end
@@ -34,6 +34,7 @@ module Foreigner
34
34
  case dependency
35
35
  when :nullify then "ON DELETE SET NULL"
36
36
  when :delete then "ON DELETE CASCADE"
37
+ when :restrict then "ON DELETE RESTRICT"
37
38
  else ""
38
39
  end
39
40
  end
@@ -47,6 +47,14 @@ class MysqlAdapterTest < ActiveRecord::TestCase
47
47
  )
48
48
  end
49
49
 
50
+ def test_add_with_restrict_dependency
51
+ assert_equal(
52
+ "ALTER TABLE `employees` ADD CONSTRAINT `employees_company_id_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id) " +
53
+ "ON DELETE RESTRICT",
54
+ add_foreign_key(:employees, :companies, :dependent => :restrict)
55
+ )
56
+ end
57
+
50
58
  def test_remove_by_table
51
59
  assert_equal(
52
60
  "ALTER TABLE `suppliers` DROP FOREIGN KEY `suppliers_company_id_fk`",
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matthuhiggins-foreigner
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 63
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 7
8
- - 1
9
- version: 0.7.1
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Matthew Higgins
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-06 00:00:00 -07:00
18
+ date: 2010-09-16 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -53,6 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
54
  requirements:
54
55
  - - ">="
55
56
  - !ruby/object:Gem::Version
57
+ hash: 59
56
58
  segments:
57
59
  - 1
58
60
  - 8
@@ -63,6 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  requirements:
64
66
  - - ">="
65
67
  - !ruby/object:Gem::Version
68
+ hash: 17
66
69
  segments:
67
70
  - 1
68
71
  - 3