@@ -14,7 +14,7 @@ module Builder
1414 # === Options
1515 # [:class_name]
1616 # Specify the class name of the association. This class name would
17- # be used for resolving the association class.
17+ # be used for resolving the association class.
1818 #
1919 # ==== Example for [:class_name] - option
2020 # GET /posts/123.json delivers following response body:
@@ -48,7 +48,7 @@ def has_many(name, options = {})
4848 # === Options
4949 # [:class_name]
5050 # Specify the class name of the association. This class name would
51- # be used for resolving the association class.
51+ # be used for resolving the association class.
5252 #
5353 # ==== Example for [:class_name] - option
5454 # GET /posts/1.json delivers following response body:
@@ -74,7 +74,7 @@ def has_one(name, options = {})
7474 end
7575
7676 # Specifies a one-to-one association with another class. This class should only be used
77- # if this class contains the foreign key.
77+ # if this class contains the foreign key.
7878 #
7979 # Methods will be added for retrieval and query for a single associated object, for which
8080 # this object holds an id:
@@ -83,7 +83,7 @@ def has_one(name, options = {})
8383 # Returns the associated object. +nil+ is returned if the foreign key is +nil+.
8484 # Throws a ActiveResource::ResourceNotFound exception if the foreign key is not +nil+
8585 # and the resource is not found.
86- #
86+ #
8787 # (+association+ is replaced with the symbol passed as the first argument, so
8888 # <tt>belongs_to :post</tt> would add among others <tt>post.nil?</tt>.
8989 #
@@ -130,8 +130,8 @@ def defines_belongs_to_finder_method(method_name, association_model, finder_key)
130130 instance_variable_get ( ivar_name )
131131 elsif attributes . include? ( method_name )
132132 attributes [ method_name ]
133- else
134- instance_variable_set ( ivar_name , association_model . find ( send ( finder_key ) ) )
133+ elsif association_id = send ( finder_key )
134+ instance_variable_set ( ivar_name , association_model . find ( association_id ) )
135135 end
136136 end
137137 end
@@ -149,7 +149,7 @@ def defines_has_many_finder_method(method_name, association_model)
149149 end
150150 end
151151 end
152-
152+
153153 # Defines the has_one association
154154 def defines_has_one_finder_method ( method_name , association_model )
155155 ivar_name = :"@#{ method_name } "
0 commit comments