@@ -184,15 +184,18 @@ def add_relationship(relationship)
184184 end
185185
186186 def has_many ( relationship_name , options = { } , &block )
187- create_relationship ( relationship_name , :has_many , options , block )
187+ relationship = create_relationship ( relationship_name , :has_many , options , block )
188+ add_relationship ( relationship )
188189 end
189190
190191 def has_one ( relationship_name , options = { } , &block )
191- create_relationship ( relationship_name , :has_one , options , block )
192+ relationship = create_relationship ( relationship_name , :has_one , options , block )
193+ add_relationship ( relationship )
192194 end
193195
194196 def belongs_to ( relationship_name , options = { } , &block )
195- create_relationship ( relationship_name , :belongs_to , options , block )
197+ relationship = create_relationship ( relationship_name , :belongs_to , options , block )
198+ add_relationship ( relationship )
196199 end
197200
198201 def create_relationship ( base_key , relationship_type , options , block )
@@ -206,7 +209,7 @@ def create_relationship(base_key, relationship_type, options, block)
206209 base_key_sym = name
207210 id_postfix = '_id'
208211 end
209- relationship = Relationship . new (
212+ Relationship . new (
210213 key : options [ :key ] || run_key_transform ( base_key ) ,
211214 name : name ,
212215 id_method_name : options [ :id_method_name ] || "#{ base_serialization_key } #{ id_postfix } " . to_sym ,
@@ -219,7 +222,6 @@ def create_relationship(base_key, relationship_type, options, block)
219222 polymorphic : fetch_polymorphic_option ( options ) ,
220223 conditional_proc : options [ :if ]
221224 )
222- add_relationship ( relationship )
223225 end
224226
225227 def compute_serializer_name ( serializer_key )
0 commit comments