]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
cleanup forms
authorAndrey Kutejko <andy128k@gmail.com>
Mon, 25 Aug 2014 14:56:50 +0000 (17:56 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 26 Aug 2014 15:45:34 +0000 (18:45 +0300)
ipf/legacy_orm/modelform.php

index 89ffed1e25283dc549f85dc2999490b6715f4a54..fe9cb9344bf3d387d07dfa448ecbb71aeeab4830 100644 (file)
@@ -174,19 +174,23 @@ class IPF_Form_Model extends IPF_Form
         );
 
         if ($rt === IPF_ORM_Relation::ONE_AGGREGATE) {
-            $params['queryset'] = $table->findAll();
-            return array($name.'_id', new IPF_Form_Field_ModelChoice($params));
-        } elseif ($rt === IPF_ORM_Relation::MANY_AGGREGATE) {
-
+            $choices = array('--------' => '');
             $pk = $table->getIdentifier();
+            foreach ($table->findAll() as $o) {
+                $choices[$o->__toString()] = $o->$pk;
+            }
+
+            $params['choices'] = $choices;
+            return array($name.'_id', new IPF_Form_Field_Choice($params));
+        } elseif ($rt === IPF_ORM_Relation::MANY_AGGREGATE) {
             $choices = array();
+            $pk = $table->getIdentifier();
             foreach ($table->findAll() as $o) {
                 $choices[$o->__toString()] = $o->$pk;
             }
 
             $params['choices'] = $choices;
-            $params['widget']  = 'IPF_Form_Widget_SelectMultipleInput';
-            return array($name, new IPF_Form_Field_ModelMultipleChoice($params));
+            return array($name, new IPF_Form_Field_MultipleChoice($params));
         } else {
             return null;
         }