From ac946c6a1e56b17ced2a902f149dbd33412c7dd0 Mon Sep 17 00:00:00 2001 From: avl Date: Sat, 8 Nov 2008 21:49:29 +0200 Subject: [PATCH] ManyToMany Field allow misc pk --- ipf/admin/model.php | 3 ++- ipf/form/db/manytomany.php | 3 ++- ipf/form/model.php | 3 ++- ipf/form/widget/selectmultipleinput.php | 2 +- ipf/orm/record.php | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ipf/admin/model.php b/ipf/admin/model.php index 8d5144e..0344fd0 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -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; } } } diff --git a/ipf/form/db/manytomany.php b/ipf/form/db/manytomany.php index 2188498..3e890c6 100644 --- a/ipf/form/db/manytomany.php +++ b/ipf/form/db/manytomany.php @@ -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'])) { diff --git a/ipf/form/model.php b/ipf/form/model.php index 171ccd2..1a25420 100644 --- a/ipf/form/model.php +++ b/ipf/form/model.php @@ -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; diff --git a/ipf/form/widget/selectmultipleinput.php b/ipf/form/widget/selectmultipleinput.php index 6e234c2..35e38fd 100644 --- a/ipf/form/widget/selectmultipleinput.php +++ b/ipf/form/widget/selectmultipleinput.php @@ -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('', htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'), $selected, diff --git a/ipf/orm/record.php b/ipf/orm/record.php index db6328d..8521f5c 100644 --- a/ipf/orm/record.php +++ b/ipf/orm/record.php @@ -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; -- 2.49.0