]> git.andy128k.dev Git - ipf.git/commitdiff
admin: fix relations detection
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 14 Sep 2013 15:41:13 +0000 (18:41 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 14 Sep 2013 15:41:13 +0000 (18:41 +0300)
ipf/admin/model.php

index c702c63cdca55495c904c4ba365344505f15b60a..a52e1900c8662cfa2d0f3a28772e150d8a30e87c 100644 (file)
@@ -645,8 +645,7 @@ class IPF_Admin_Model
         if ($perms === false || !in_array('view', $perms))
             return new IPF_HTTP_Response_NotFound($request);
 
-        if ($request->method == 'POST')
-        {
+        if ($request->method == 'POST') {
             if (!in_array('change', $perms))
                 return new IPF_HTTP_Response_NotFound($request);
 
@@ -655,8 +654,7 @@ class IPF_Admin_Model
             $form = $this->_getEditForm($o, $data, array('user_fields'=>$this->fields()));
             $this->_setupEditForm($form);
             $this->setInlines($o, $data);
-            if ( ($form->isValid()) && ($this->isValidInlines()) )
-            {
+            if ( ($form->isValid()) && ($this->isValidInlines()) ) {
                 $item = $form->save();
                 $this->saveInlines($item);
                 AdminLog::logAction($request, $item, AdminLog::CHANGE);
@@ -666,18 +664,13 @@ class IPF_Admin_Model
                     $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
                 return new IPF_HTTP_Response_Redirect($url);
             }
-        }
-        else
-        {
+        } else {
             $data = $o->getData();
-            foreach ($o->getTable()->getRelations() as $rname=>$rel)
-            {
+            foreach ($o->getTable()->getRelations() as $rname => $rel) {
                 $pk = $rel->getTable()->getIdentifier();
                 $fields = $this->fields();
-                if ($fields && array_search($rname, $fields))
-                {
-                    if ($rel->getType()==IPF_ORM_Relation::MANY_AGGREGATE)
-                    {
+                if (!$fields || in_array($rname, $fields)) {
+                    if ($rel->getType() == IPF_ORM_Relation::MANY_AGGREGATE) {
                         $data[$rname] = array();
                         foreach ($rel->fetchRelatedFor($o) as $ri)
                             $data[$rname][] = $ri->$pk;