OSDN Git Service

fix remove tree
[pettanr/pettanr.git] / lib / manifest / model / association / has_many.rb
index 063fdcf..98ed731 100644 (file)
@@ -1,26 +1,24 @@
 module Manifest
   module ModelModule
     module AssociationModule
-      class HasMany
-        attr :association, :has_many_name, :has_many_manifest, 
-          :model_name, :foreign_key, :through
-        def initialize association, has_many_name, has_many_manifest
-          @association = association
-          @has_many_name = has_many_name
-          @has_many_manifest = has_many_manifest
-          self.set_default
-          self.init
-        end
+      class HasMany < ManifestBase::NameValues
+        attr :model_name, :foreign_key, :through
         
         def set_default
-          @has_many_manifest['model_name'] ||= @has_many_name.singularize
-          @has_many_manifest['foreign_key'] ||= @association.model_name + '_id'
+          super
+          @values['model_name'] ||= ::Manifest.singularize @name
+          @values['foreign_key'] ||= @parent.model_name + '_id'
         end
         
         def init
-          @model_name = @has_many_manifest['model_name']
-          @foreign_key = @has_many_manifest['foreign_key']
-          @through = @has_many_manifest['through']
+          super
+          @model_name = @values['model_name']
+          @foreign_key = @values['foreign_key']
+          @through = @values['through']
+        end
+        
+        def through?
+          @through.blank? == false
         end
         
         def model
@@ -28,7 +26,7 @@ module Manifest
         end
         
         def association_name
-          @association.association_name
+          @parent.association_name
         end
         
       end