This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » admin gen module & I18N fields -> sF tries to save Object's Translation before Object...!
admin gen module & I18N fields -> sF tries to save Object's Translation before Object...! [message #98862] Tue, 11 May 2010 12:38
shopoto
Messages: 19
Registered: July 2009
Junior Member
Hi everyone

I'm using Sf 1,2,7


I tried a very simple case

Here is my modele:

options:
  collate: utf8_unicode_ci
  charset: utf8

medias:
  tableName: medias
  actAs:
    I18n:
      fields: [nom, legende, description] 
    #Signable:
    Timestampable:
    Sluggable:
     unique: true
     fields: [nom]
     canUpdate: true
  columns:
    mid: { type: integer(4), primary: true, autoincrement: true }
    mtid: { type: integer(4), notnull: true }
    content_model: { type: string(100), notnull: false }
    nom: { type: string(100), notnull: false }
    legende: { type: string(255), notnull: false }
    description: { type: string(255) }    
    mime: { type: string(50) }
    largeur: { type: integer(2), notnull: true }
    hauteur: { type: integer(2), notnull: true }
    url: { type: string(255), notnull: true }

mediasTypes:
  tableName: medias_types
  columns:
    mtid: { type: integer(4), primary: true, autoincrement: true }
    label: { type: string(100), notnull: true }    



As you can the model is very simple

With that, I have juste generated a new admin gen module based on the medias class.

Then I overloaded the PluginMediaForm.class.php like this:
<?php

/**
 * Pluginmedias form.
 *
 * @package    form
 * @subpackage medias
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
abstract class PluginmediasForm extends BasemediasForm
{
	public function setup()
	{
		parent::setup();
		unset
		(
		//$this['paragraphes_list'],
		$this['mtid'],
		$this['updated_at'],
		$this['created_at'],
		$this['mime'],
		$this['largeur'],
		$this['hauteur'],
		$this['slug'],
        $this['contenus_list']
		);

		$content_model=$this->getObject()->content_model;
		if(empty($content_model))
		{
			$content_model="contenus";
		}

        
		$this->embedI18n(array( "fr"));
        foreach( array( "fr" => "Fran├žais" ) as $lang => $label )
        {
          $this->widgetSchema->setLabel($lang, $label );
        }
 
        $widgetUrl = new sfWidgetFormInputFileEditable(array(
          'file_src' => sfConfig::get('sf_upload_dir').$this->getObject()->getUrl(),
          'is_image' => false,
          //'edit_mode' => !$this->isNew(),
          'edit_mode' => false,
          'with_delete' => true,
        ));

        $validatorUrl = new sfValidatorFile(array(
            'required' => false,
            'path' => sfConfig::get('sf_upload_dir'),
            //'mime_types' => $tab_allowed_mime_extensions
            'mime_types' => 'web_images'
        ));

        $this->setWidget("url", $widgetUrl);
        $this->setValidator("url", $validatorUrl);

	$this->setWidget('content_model',new sfWidgetFormInputHidden());
	$this->setDefault('content_model',$content_model);

	$this->setValidator('largeur', new sfValidatorPass());
	$this->setValidator('hauteur', new sfValidatorPass());


	$this->widgetSchema->setLabel('mid', 'Media');

	}

}



The problem is when I try to fill and submit the admin gen media new form I get this error:

500 | Internal Server Error | Doctrine_Connection_Mysql_Exception
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'mid' cannot be null
stack trace

    * at ()
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 1086 ...
            1083.         
            1084.         $name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
            1085.
            1086.         $exc  = new $name($e->getMessage(), (int) $e->getCode());
            1087.         if ( ! isset($e->errorInfo) || ! is_array($e->errorInfo)) {
            1088.             $e->errorInfo = array(null, null, null, null);
            1089.         }
    * at Doctrine_Connection->rethrowException(object('PDOException'), object('Doctrine_Connection_Statement'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/Statement.php line 253 ...
             250.         } catch (Doctrine_Adapter_Exception $e) {
             251.         }
             252.
             253.         $this->_conn->rethrowException($e, $this);
             254.
             255.         return false;
             256.     } 
    * at Doctrine_Connection_Statement->execute(array(null, 'fr', 'djy', 'dy', 'di'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 1051 ...
            1048.         try {
            1049.             if ( ! empty($params)) {
            1050.                 $stmt = $this->prepare($query);
            1051.                 $stmt->execute($params);
            1052.
            1053.                 return $stmt->rowCount();
            1054.             } else {
    * at Doctrine_Connection->exec('INSERT INTO medias_translation (mid, lang, nom, legende, description) VALUES (?, ?, ?, ?, ?)', array(null, 'fr', 'djy', 'dy', 'di'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 684 ...
             681.                 . ' (' . implode(', ', $cols) . ')'
             682.                 . ' VALUES (' . implode(', ', $a) . ')';
             683.
             684.         return $this->exec($query, array_values($fields));
             685.     }
             686.
             687.     /**
    * at Doctrine_Connection->insert(object('Doctrine_Table'), array(null, 'lang' => 'fr', 'nom' => 'djy', 'legende' => 'dy', 'description' => 'di'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 631 ...
             628.             $record->assignIdentifier($id);
             629.         }
             630.
             631.         $this->conn->insert($table, $fields);
             632.
             633.         if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() &&
             634.             $table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
    * at Doctrine_Connection_UnitOfWork->processSingleInsert(object('mediasTranslation'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 590 ...
             587.                     $this->_insertCTIRecord($table, $record);
             588.                     //--
             589.                 } else {
             590.                     $this->processSingleInsert($record);
             591.                 }
             592.             }
 593.
    * at Doctrine_Connection_UnitOfWork->insert(object('mediasTranslation'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 84 ...
              81.                 switch ($state) {
              82.                     case Doctrine_Record::STATE_TDIRTY:
              83.                     case Doctrine_Record::STATE_TCLEAN:
              84.                         $isValid = $this->insert($record);
              85.                         break;
              86.                     case Doctrine_Record::STATE_DIRTY:
              87.                     case Doctrine_Record::STATE_PROXY:
    * at Doctrine_Connection_UnitOfWork->saveGraph(object('mediasTranslation'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1329 ...
            1326.         if ($conn === null) {
            1327.             $conn = $this->_table->getConnection();
            1328.         }
            1329.         $conn->unitOfWork->saveGraph($this);
            1330.     }
            1331.
            1332.     /** 
    * at Doctrine_Record->save(object('Doctrine_Connection_Mysql'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Collection.php line 827 ...
             824.             }
             825.
             826.             foreach ($this->getData() as $key => $record) {
             827.                 $record->save($conn);
             828.             }
             829.
             830.             $conn->commit();
    * at Doctrine_Collection->save(object('Doctrine_Connection_Mysql'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 131 ...
             128. //                    echo "<br />";
             129.                     // check that the related object is not an instance of Doctrine_Null
             130.                     if ($obj && ! ($obj instanceof Doctrine_Null)) {
             131.                         $obj->save($conn);
             132.                     }
             133.                 }
             134.             }
    * at Doctrine_Connection_UnitOfWork->saveGraph(object('medias'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1329 ...
            1326.         if ($conn === null) {
            1327.             $conn = $this->_table->getConnection();
            1328.         }
            1329.         $conn->unitOfWork->saveGraph($this);
            1330.     }
            1331.
            1332.     /** 
    * at Doctrine_Record->save(object('Doctrine_Connection_Mysql'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php line 364 ...
             361.
             362.     $this->updateObject();
             363.
             364.     $this->object->save($con);
             365.
             366.     // embedded forms
             367.     $this->saveEmbeddedForms($con);
    * at sfFormDoctrine->doSave(object('Doctrine_Connection_Mysql'))
      in SF_SYMFONY_LIB_DIR/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php line 179 ...
             176.     {
             177.       $con->beginTransaction();
             178.
             179.       $this->doSave($con);
             180.
             181.       $con->commit();
             182.     }
    * at sfFormDoctrine->save()
      in SF_ROOT_DIR/cache/backend/dev/modules/autoMedias/actions/actions.class.php line 194 ...
             191.     {
             192.       $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
             193.
             194.       $medias = $form->save();
             195.
             196.       $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $medias)));
 197.
    * at autoMediasActions->processForm(object('sfWebRequest'), object('mediasForm'))
      in SF_ROOT_DIR/cache/backend/dev/modules/autoMedias/actions/actions.class.php line 86 ...
              83.     $this->form = $this->configuration->getForm();
              84.     $this->medias = $this->form->getObject();
              85.
              86.     $this->processForm($request, $this->form);
              87.
              88.     $this->setTemplate('new');
              89.   }
    * at autoMediasActions->executeCreate(object('sfWebRequest'))
      in SF_SYMFONY_LIB_DIR/action/sfActions.class.php line 53 ...
              50.     }
              51.
              52.     // run action
              53.     return $this->$actionToRun($request);
              54.   }
              55. }
  56.
    * at sfActions->execute(object('sfWebRequest'))
      in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 90 ...
              87.   {
              88.     // execute the action
              89.     $actionInstance->preExecute();
              90.     $viewName = $actionInstance->execute($this->context->getRequest());
              91.     $actionInstance->postExecute();
              92.
              93.     return is_null($viewName) ? sfView::SUCCESS : $viewName;
    * at sfExecutionFilter->executeAction(object('mediasActions'))
      in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 76 ...
              73.       return sfView::SUCCESS;
              74.     }
              75.
              76.     return $this->executeAction($actionInstance);
              77.   }
              78.
              79.   /**
    * at sfExecutionFilter->handleAction(object('sfFilterChain'), object('mediasActions'))
      in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 42 ...
              39.     {
              40.       $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName()));
              41.
              42.       $viewName = $this->handleAction($filterChain, $actionInstance);
              43.
              44.       $timer->addTime();
              45.       $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName()));
    * at sfExecutionFilter->execute(object('sfFilterChain'))
      in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
              50.       }
              51.
              52.       // execute the next filter
              53.       $this->chain[$this->index]->execute($this);
              54.     }
              55.   }
  56.
    * at sfFilterChain->execute()
      in SF_SYMFONY_LIB_DIR/filter/sfCommonFilter.class.php line 29 ...
              26.   public function execute($filterChain)
              27.   {
              28.     // execute next filter
              29.     $filterChain->execute();
              30.
              31.     // execute this filter only once
              32.     $response = $this->context->getResponse();
    * at sfCommonFilter->execute(object('sfFilterChain'))
      in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
              50.       }
              51.
              52.       // execute the next filter
              53.       $this->chain[$this->index]->execute($this);
              54.     }
              55.   }
  56.
    * at sfFilterChain->execute()
      in SF_SYMFONY_LIB_DIR/filter/sfRenderingFilter.class.php line 33 ...
              30.   public function execute($filterChain)
              31.   {
              32.     // execute next filter
              33.     $filterChain->execute();
              34.
              35.     // get response object
              36.     $response = $this->context->getResponse();
    * at sfRenderingFilter->execute(object('sfFilterChain'))
      in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
              50.       }
              51.
              52.       // execute the next filter
              53.       $this->chain[$this->index]->execute($this);
              54.     }
              55.   }
  56.
    * at sfFilterChain->execute()
      in SF_SYMFONY_LIB_DIR/controller/sfController.class.php line 245 ...
             242.       }
             243.
             244.       // process the filter chain
             245.       $filterChain->execute();
             246.     }
             247.     else
             248.     {
    * at sfController->forward('medias', 'create')
      in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 48 ...
              45.       }
              46.
              47.       // make the first request
              48.       $this->forward($moduleName, $actionName);
              49.     }
              50.     catch (sfException $e)
              51.     {
    * at sfFrontWebController->dispatch()
      in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 159 ...
             156.    */
             157.   public function dispatch()
             158.   {
             159.     $this->getController()->dispatch();
             160.   }
             161.
             162.   /**
    * at sfContext->dispatch()
      in SF_ROOT_DIR/web/backend_dev.php line 13 ...


I do not understand why sf trie to save media's translation
before the media object, which obviously leads to an error (Prim key mid can't be null)

I just know that this problem is not due to the bug related in:
http://trac.symfony-project.org/changeset/15243

cause my code is not yet entered the saveEmbeddedForms methods.
My code is stile in Object->save() when this error come.

I just know that this error deals with Unit of Works trie to save related components in saveGraph().
In my case it tries to save (mediasTranslation) in order to save my medias Object...

Any help would be appreciate!
Previous Topic:[solved] iconv cyrillic (russian)
Next Topic:Chane action template name
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software