decisiv-sharded_database 0.3.2.1 → 0.3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/sharded_database.rb
CHANGED
@@ -3,12 +3,11 @@ module ShardedDatabase
|
|
3
3
|
|
4
4
|
def self.included(klass)
|
5
5
|
klass.class_eval do
|
6
|
-
alias_method_chain :initialize, :
|
7
|
-
#alias_method_chain :find, :connection
|
6
|
+
alias_method_chain :initialize, :delegated_connection
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
10
|
+
def initialize_with_delegated_connection(owner, reflection)
|
12
11
|
if @connection_class = reflection.options[:connection_class]
|
13
12
|
@original_class = reflection.klass
|
14
13
|
reflection.metaclass.class_eval %{
|
@@ -17,21 +16,10 @@ module ShardedDatabase
|
|
17
16
|
end
|
18
17
|
}
|
19
18
|
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def find_with_connection(*args)
|
24
|
-
if connection_class = @reflection.options[:connection_class]
|
25
|
-
ShardedDatabase::ModelWithConnection.borrow_connection(@reflection.klass, connection_class) do
|
26
|
-
find_without_connection(*args)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
find_without_connection(*args)
|
30
|
-
end
|
19
|
+
initialize_without_delegated_connection(owner, reflection)
|
31
20
|
end
|
32
21
|
|
33
22
|
end
|
34
23
|
end
|
35
24
|
|
36
|
-
ActiveRecord::Associations::HasManyAssociation.send :include, ShardedDatabase::HasManyAssociation
|
37
|
-
ActiveRecord::Associations::HasManyThroughAssociation.send :include, ShardedDatabase::HasManyAssociation
|
25
|
+
ActiveRecord::Associations::HasManyAssociation.send :include, ShardedDatabase::HasManyAssociation
|