[FLOW3-general] Problem With Update

daniel andrew daniel.andrew91 at gmail.com
Mon Apr 2 15:11:27 CEST 2012


Hello,

I have a problem with update in flow3. Basicly i have 2 tables in MySql.
The first table called translatiounit and it has fields: translationsource,
translationkey, translationpackage. The second table called
translationtarget and it has fields: translationtarget,
translationlanguage, translationapproval, comment, translationunit.

The problem is, i have to update those fields from different table in 1
form. How to do that? should i create new method in the repository or is
there any other better way to do that?  this is my code in controller to do
update:

/**
 * create action
 * @param \Somea\Translation\Domain\Model\TranslationUnit $unit A new unit
to add
         * @param \Somea\Translation\Domain\Model\TranslationPackage
$package A new Package to add
         * @param \Somea\Translation\Domain\Model\TranslationLanguage
$language A new Language to add
         * @param string $translationTarget
         * @param string $translationApproval
         * @param string $comment
 * @return void
 */
public function updateAction(TranslationUnit $unit, TranslationPackage
$package, TranslationLanguage $language, $translationTarget,
$translationApproval, $comment) {
                $this->translationUnitRepository->update($unit);
                $targetObject  = new Translationtarget();
                $targetObject->setTranslationTarget($translationTarget);
                $targetObject->setTranslationApproval($translationApproval);
                $targetObject->setComment($comment);
                $targetObject->setTranslationLanguage($language);
                $targetObject->setTranslationUnit($unit);
                $this->translationTargetRepository->update($targetObject);

$this->redirect('index','TranslationUnit','Somea.Translation',array('language'
=> $language, 'package' => $package));
}

and this is my model:

   - the translationunit model:

    /*
   *
 * This script belongs to the FLOW3 package "Somea.Translation".          *
 *                                                                        *
 *                                                                        */

use TYPO3\FLOW3\Annotations as FLOW3;
use Doctrine\ORM\Mapping as ORM;

/**
 * A Translation unit
 *
 * @FLOW3\Scope("prototype")
 * @FLOW3\Entity
 */
class TranslationUnit {

/**
 * The translationkey
 * @var string
 */
protected $translationKey;

/**
 * The translationsource
 * @var string
 */
protected $translationSource;


/**
 * The translationpackage
 * @var \Somea\Translation\Domain\Model\TranslationPackage
         * @ORM\ManyToOne(inversedBy="translationUnit")
 */
protected $translationPackage;


        /** The flow3_persistence_identifier
         *
         * @var string
         * @ORM\Id
         * @ORM\Column(name="flow3_persistence_identifier", type="string",
length=40)
         */
        protected $FLOW3_Persistence_Identifier;


/**
 * Get the Translation unit's key
 *
 * @return string The Translation unit's key
 */
public function getTranslationKey() {
return $this->translationKey;
}

/**
 * Sets this Translation unit's key
 *
 * @param string $translationKey The Translation unit's key
 * @return void
 */
public function setTranslationKey($translationKey) {
$this->translationKey = $translationKey;
}

/**
 * Get the Translation unit's source
 *
 * @return string The Translation unit's source
 */
public function getTranslationSource() {
return $this->translationSource;
}

/**
 * Sets this Translation unit's source
 *
 * @param string $source The Translation unit's source
 * @return void
 */
public function setTranslationSource($translationSource) {
$this->translationSource = $translationSource;
}




/**
 * Get the Translation unit's translationpackage
 *
 * @return \Somea\Translation\Domain\Model\TranslationPackage The
Translation unit's translationpackage
 */
public function getTranslationPackage() {
return $this->translationPackage;
}

/**
 * Sets this Translation unit's translationpackage
 *
 * @param \Somea\Translation\Domain\Model\TranslationPackage
$translationpackage The Translation unit's translationpackage
 * @return void
 */
public function
setTranslationPackage(\Somea\Translation\Domain\Model\TranslationPackage
$translationPackage) {
$this->translationPackage = $translationPackage;
}

}


-and translationtarget model:
 /*                                                                        *
 * This script belongs to the FLOW3 package "Somea.Translation".          *
 *                                                                        *
 *                                                                        */

use TYPO3\FLOW3\Annotations as FLOW3;
use Doctrine\ORM\Mapping as ORM;

/**
 * A Translation target
 *
 * @FLOW3\Scope("prototype")
 * @FLOW3\Entity
 */
class TranslationTarget {

        /**
 * The translation target
 * @var string
 */
protected $translationTarget;

        /**
 * The translation approval
 * @var string
 */
protected $translationApproval;

        /**
 * The translation comment
 * @var string
 */
protected $comment;

        /**
 * The translationlanguage
 * @var \Somea\Translation\Domain\Model\TranslationLanguage
         * @ORM\ManyToOne(inversedBy="translationTarget")
 */
protected $translationLanguage;

        /**
 * The translationlanguage
 * @var \Somea\Translation\Domain\Model\TranslationUnit
         * @ORM\ManyToOne(inversedBy="translationTarget")
 */
protected $translationUnit;

        /**
 * Get the Translation target's target
 *
 * @return string The Translation target's target
 */
public function getTranslationTarget() {
return $this->translationTarget;
}

/**
 * Sets this Translation target's target
 *
 * @param string $translationTarget The Translation target's target
 * @return void
 */
public function setTranslationTarget($translationTarget) {
$this->translationTarget = $translationTarget;
}



        /**
 * Get the Translation target's approval
 *
 * @return string The Translation target's approval
 */
public function getTranslationApproval() {
return $this->translationApproval;
}

/**
 * Sets this Translation target's approval
 *
 * @param string $translationApproval The Translation target's approval
 * @return void
 */
public function setTranslationApproval($translationApproval) {
$this->translationApproval = $translationApproval;
}

         /**
 * Get the Translation target's comment
 *
 * @return string The Translation target's comment
 */
public function getComment() {
return $this->comment;
}

/**
 * Sets this Translation target's comment
 *
 * @param string $comment The Translation target's comment
 * @return void
 */
public function setComment($comment) {
$this->comment = $comment;
}


/**
 * Get the Translation target's translationlanguage
 *
 * @return \Somea\Translation\Domain\Model\TranslationLanguage The
Translation unit's translationlanguage
 */
public function getTranslationLanguage() {
return $this->translationLanguage;
}

/**
 * Sets this Translation target's translationlanguage
 *
 * @param \Somea\Translation\Domain\Model\TranslationLanguage
$translationlanguage The Translation unit's translationlanguage
 * @return void
 */
public function
setTranslationLanguage(\Somea\Translation\Domain\Model\TranslationLanguage
$translationLanguage) {
$this->translationLanguage = $translationLanguage;
}

        /**
 * Get the Translation target's translationunit
 *
 * @return \Somea\Translation\Domain\Model\TranslationUnit The Translation
unit's translationunit
 */
public function getTranslationUnit() {
return $this->translationUnit;
}

/**
 * Sets this Translation target's translationlanguage
 *
 * @param \Somea\Translation\Domain\Model\TranslationUnit $translationUnit
The Translation unit's translationunit
 * @return void
 */
public function
setTranslationUnit(\Somea\Translation\Domain\Model\TranslationUnit
$translationUnit) {
$this->translationUnit = $translationUnit;
}



}



if i execute this action, it will throw an error: *: The object of type
"TranslationTarget" given to update must be persisted already, but is new*

Please let me know if there is any questions about my explanation or you
need something else.

Best Regards,

Daniel


More information about the FLOW3-general mailing list