Permalink
Browse files

Quick hack to get it to work with rails 3.2

  • Loading branch information...
1 parent 4bab724 commit 49f07053ba94e353b587ee81be8e32e714986ca3 @ajrkerr committed Jan 23, 2012
Showing with 15 additions and 7 deletions.
  1. +14 −6 lib/build_associated.rb
  2. +1 −1 lib/build_associated/version.rb
View
@@ -5,13 +5,21 @@ module BuildAssociated
module ClassMethods
def build_associated association_name
- alias_method "_#{association_name}", association_name
- remove_method association_name
+ begin
+ alias_method "_#{association_name}", association_name
+ remove_method(association_name)
- define_method association_name do
- obj = self.send("_#{association_name}")
- obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
- return obj
+ define_method association_name do
+ obj = self.send("_#{association_name}") || super
+ obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
+ return obj
+ end
+ rescue NameError
+ define_method association_name do
+ obj = super
+ obj ||= self.send("build_#{association_name}") unless self.frozen? or self.readonly?
+ return obj
+ end
end
end
end
@@ -1,3 +1,3 @@
module BuildAssociated
- VERSION = "1.0.1"
+ VERSION = "1.1.2"
end

0 comments on commit 49f0705

Please sign in to comment.