johnsbrn-classy-inheritance 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,5 @@
1
+ == 0.6.5 2009-02-01
2
+ * Add fix for has_one primary key bug - http://rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug
1
3
  == 0.6.4 2009-02-01
2
4
  * Updated deprecated default error messages - johnsbrn
3
5
  * Added has_dependency for non-polymorphic has_one - johnsbrn
@@ -1,12 +1,43 @@
1
1
  module Stonean
2
2
  module ClassyInheritance
3
- VERSION = '0.6.3.2'
3
+ VERSION = '0.6.5'
4
4
 
5
5
  def self.version
6
6
  VERSION
7
7
  end
8
8
 
9
9
  module ClassMethods
10
+
11
+ # fix active record has_one primary key bug - http://rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug
12
+ def has_one(association_id, options = {})
13
+ if options[:through]
14
+ reflection = create_has_one_through_reflection(association_id, options)
15
+ association_accessor_methods(reflection, ActiveRecord::Associations::HasOneThroughAssociation)
16
+ else
17
+ reflection = create_has_one_reflection(association_id, options)
18
+
19
+ ivar = "@#{reflection.name}"
20
+
21
+ method_name = "has_one_after_save_for_#{reflection.name}".to_sym
22
+ define_method(method_name) do
23
+ association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
24
+ if !association.nil? && (new_record? || association.new_record? || association[reflection.primary_key_name] != id)
25
+ primary_key = reflection.options[:primary_key] || :id
26
+ association[reflection.primary_key_name] = send(primary_key)
27
+ association.save(true)
28
+ end
29
+ end
30
+ after_save method_name
31
+
32
+ add_single_associated_validation_callbacks(reflection.name) if options[:validate] == true
33
+ association_accessor_methods(reflection, ActiveRecord::Associations::HasOneAssociation)
34
+ association_constructor_method(:build, reflection, ActiveRecord::Associations::HasOneAssociation)
35
+ association_constructor_method(:create, reflection, ActiveRecord::Associations::HasOneAssociation)
36
+
37
+ configure_dependency_for_has_one(reflection)
38
+ end
39
+ end
40
+
10
41
  def depends_on(model_sym, options = {})
11
42
  define_relationship(model_sym,options)
12
43
 
data/test/test_helper.rb CHANGED
@@ -30,7 +30,7 @@ class SetupTestTables < ActiveRecord::Migration
30
30
  create_table :account_logins, :force => true do |t|
31
31
  t.string :login
32
32
  t.string :password
33
- t.integer :account_id
33
+ t.string :account_email
34
34
 
35
35
  t.timestamps
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnsbrn-classy-inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone