[Nitro] target_singular_name in refers_to.rb

Rob Pitt rob at motionpath.com
Thu Oct 20 09:39:20 EDT 2005


Could anyone tell me where the variable target_singular_name comes from on line 8 in refers_to.rb? It looks like it comes from itself later on in the code but that doesn't make any sense...

The reason I ask is because if you use ObjectGraph in the fashion I described earlier (managing multiple db's where they do not have the same tables and fields on both sites) sometimes this information is missing (and on the other relations too). I think it could be related to situations where Objects are related to other Objects in interconnected ways, I patched 0.23 in horrible ways with things like:

Index: lib/og/relation/refers_to.rb
--- lib/og/relation/refers_to.rb        (revision 1)
+++ lib/og/relation/refers_to.rb        (working copy)
@@ -5,6 +5,9 @@
 class RefersTo < Relation

   def enchant
+    target_pk ||= @options[:target_class].primary_key.reject!{|pka| pka.class != Symbol}.first
+    target_pkclass ||= @options[:target_class].primary_key.reject!{|pka| pka.class == Symbol}.first
     self[:foreign_key] = "#{foreign_name || target_singular_name}_#{target_pk}"

     if self[:field]

But this is horribly hacky and there must be a cleaner way?

More information about the Nitro-general mailing list