decisiv-sharded_database 0.1.4.1 → 0.1.4.2

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.
@@ -41,6 +41,8 @@ module ShardedDatabase
41
41
  load_target.source_class = @klass
42
42
  load_target.class_eval %{
43
43
  def #{method}(*args)
44
+ return @#{method} if @#{method}
45
+
44
46
  if proxy_#{method}.respond_to?(:proxy_reflection)
45
47
  proxy_#{method}.proxy_reflection.klass.metaclass.delegate :connection, :to => self.source_class
46
48
  proxy_#{method}
@@ -49,13 +51,9 @@ module ShardedDatabase
49
51
  # Revisit this later and do it properly.
50
52
 
51
53
  reflection = self.class.reflect_on_all_associations.find { |a| a.name == :#{method} }
52
- klass = reflection.klass
53
-
54
- @original_connection = klass.connection
54
+ klass = reflection.klass
55
55
  klass.metaclass.delegate :connection, :to => self.source_class
56
- @#{method} ||= klass.find(send(reflection.primary_key_name))
57
- klass.metaclass.delegate :connection, :to => @original_connection
58
-
56
+ @#{method} ||= klass.find(send(reflection.primary_key_name))
59
57
  @#{method}
60
58
  end
61
59
  end
@@ -4,6 +4,6 @@ require 'sharded_database/core_extensions'
4
4
 
5
5
  module ShardedDatabase
6
6
 
7
- VERSION = '0.1.4.1'
7
+ VERSION = '0.1.4.2'
8
8
 
9
9
  end
@@ -26,6 +26,10 @@ class AssociationTest < ShardedDatabase::TestCase
26
26
  assert_instance_of Company, @parent.company
27
27
  end
28
28
 
29
+ should 'cache the associated object' do
30
+ assert_equal @parent.company.object_id, @parent.company.object_id
31
+ end
32
+
29
33
  end
30
34
 
31
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decisiv-sharded_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.1
4
+ version: 0.1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brennan Dunn