rein 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,12 @@ module ActiveRecord::ConnectionAdapters
21
21
  include Rein::View
22
22
  end
23
23
 
24
+ class Mysql2Adapter < AbstractAdapter
25
+ include RC::PrimaryKey
26
+ include RC::ForeignKey
27
+ include Rein::View
28
+ end
29
+
24
30
  class PostgreSQLAdapter < AbstractAdapter
25
31
  include RC::PrimaryKey
26
32
  include RC::ForeignKey
@@ -19,9 +19,25 @@ module RC
19
19
  # A foreign key constraint doesn't have an implicit index.
20
20
  add_index(referencing_table, referencing_attribute) if options[:add_index] == true
21
21
  end
22
-
23
22
  alias_method :add_foreign_key, :add_foreign_key_constraint
24
23
 
24
+ def remove_foreign_key_constraint(referencing_table, referenced_table, options = {})
25
+ referencing_attribute = options[:referencing] || "#{referenced_table.to_s.singularize}_id".to_sym
26
+ referenced_attribute = "id".to_sym
27
+
28
+ name = options[:name] || "#{referencing_attribute}_fk".to_sym
29
+
30
+ if self.class.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
31
+ execute "ALTER TABLE #{referencing_table} DROP FOREIGN KEY #{name}"
32
+ else
33
+ execute "ALTER TABLE #{referencing_table} DROP CONSTRAINT #{name}"
34
+ end
35
+
36
+ # A foreign key constraint doesn't have an implicit index.
37
+ remove_index(referencing_table, referencing_attribute) if options[:remove_index] == true
38
+ end
39
+ alias_method :remove_foreign_key, :remove_foreign_key_constraint
40
+
25
41
  private
26
42
  def referential_action(action)
27
43
  case action.to_sym
@@ -1,3 +1,3 @@
1
1
  module Rein
2
- VERSION = "0.6.0" unless defined?(Rein::VERSION)
2
+ VERSION = "0.7.0" unless defined?(Rein::VERSION)
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
7
+ - 7
8
8
  - 0
9
- version: 0.6.0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josh Bassett
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-19 00:00:00 +11:00
17
+ date: 2010-10-28 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency