]> git.andy128k.dev Git - ipf.git/commitdiff
ManyToMany Field allow misc pk
authoravl <alex.litovchenko@gmail.com>
Sat, 8 Nov 2008 19:49:29 +0000 (21:49 +0200)
committeravl <alex.litovchenko@gmail.com>
Sat, 8 Nov 2008 19:49:29 +0000 (21:49 +0200)
ipf/admin/model.php
ipf/form/db/manytomany.php
ipf/form/model.php
ipf/form/widget/selectmultipleinput.php
ipf/orm/record.php

index 8d5144ec753c6d9dd60d1375c80663812e655d2d..0344fd0a08d0e425cfdebe3eaf4d2662f668c2b0 100644 (file)
@@ -270,11 +270,12 @@ class IPF_Admin_Model{
         else{
             $data = $o->getData();
             foreach($o->getTable()->getRelations() as $rname=>$rel){
+               $pk = $rel->getTable()->getIdentifier();
                 if (array_search($rname,$this->fields())){
                     if ($rel->getType()==IPF_ORM_Relation::MANY_AGGREGATE){
                         $data[$rname] = array();
                         foreach($rel->fetchRelatedFor($o) as $ri)
-                            $data[$rname][] = $ri->id;
+                            $data[$rname][] = $ri->$pk;
                     }
                 }
             }
index 2188498ea9564e23e567ede32322a51f9c22a23d..3e890c6cbf65970c24545a4afc333dd9f50c9323 100644 (file)
@@ -8,9 +8,10 @@ class IPF_Form_DB_Manytomany extends IPF_Form_DB
     {
         //print_r($def);
         $list_objects = IPF_ORM::getTable($def['model'])->findAll();
+        $pk = IPF_ORM::getTable($def['model'])->getIdentifier();
         $choices = array();
         foreach($list_objects as $o){
-            $choices[$o->__toString()] = $o->id;
+            $choices[$o->__toString()] = $o->$pk;
         }
         $def['choices'] = $choices;
         if (!isset($def['widget'])) {
index 171ccd24f7879e332b8587026915ee42152b19b8..1a254204442b8ad2ed99d7b1cd89dee8f98c13f6 100644 (file)
@@ -120,8 +120,9 @@ class IPF_Form_Model extends IPF_Form
                     if (isset($this->cleaned_data[$rname])){
                         //print $rel->getAlias();
                         $this->model->unlink($rel->getAlias());
-                        if (is_array($this->cleaned_data[$rname]))
+                        if (is_array($this->cleaned_data[$rname])){
                             $this->model->link($rel->getAlias(),$this->cleaned_data[$rname]);
+                        }
                     }
                 }
                 return $this->model;
index 6e234c235ef8e944f26f45f90af046dcda9e10f6..35e38fd00b2e8c2534b6a65db341aee075a5b5d9 100644 (file)
@@ -27,7 +27,7 @@ class IPF_Form_Widget_SelectMultipleInput extends IPF_Form_Widget
         $choices = array_merge($this->choices, $choices);
 
         foreach ($choices as $option_label=>$option_value) {
-            $selected = (in_array($option_value, $value)) ? ' selected="selected"':'';
+            $selected = (@in_array($option_value, $value)) ? ' selected="selected"':'';
             $output[] = sprintf('<option value="%s"%s>%s</option>',
                                 htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
                                 $selected,
index db6328d65e899beee4ea8102d922e6dd061b5933..8521f5c17cf2b546b3bce61ad82706ad0791da85 100644 (file)
@@ -1157,6 +1157,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                     $ids[$i] = (integer) $ids[$i];
                 }
             }
+
             foreach ($ids as $id) {
                 $record = new $modelClassName;
                 $record[$localFieldName]   = $identifier;