Skip to content
This repository
Browse code

- add has_one method

  • Loading branch information...
commit 792ee32c2688930b989a6ab876f44d1f89d06430 1 parent 5f3d639
Justin Mui authored May 16, 2012

Showing 1 changed file with 5 additions and 3 deletions. Show diff stats Hide diff stats

  1. 8  lib/simple_record/attributes.rb
8  lib/simple_record/attributes.rb
@@ -235,8 +235,10 @@ def has_many(*args)
235 235
         #I couldn't pass the id when calling find, since the original find doesn't work that way, so I was left with this.
236 236
       end
237 237
 
238  
-      def has_one(*args)
239  
-
  238
+      def has_many(association_id, options = {})
  239
+        send(:define_method, association_id) do
  240
+          return eval(%{Activerecordtosdb_subrecord_array.new('#{options[:class_name] ? options[:class_name] : association_id}', '#{options[:class_name] ? association_id.to_s : self.class.name}', id)}).first
  241
+        end
240 242
       end
241 243
 
242 244
 
@@ -437,4 +439,4 @@ def init_value(value)
437 439
     end
438 440
 
439 441
   end
440  
-end
  442
+end

0 notes on commit 792ee32

Please sign in to comment.
Something went wrong with that request. Please try again.