Hi MP,

My project is single web app, so the i'm find the entity by entitymanager 
find:
...
/** @Action(url="/{id:[0-9]+}", method="GET") */
public function getProfilePerson($id){
$entity = $this->profilePersonService->find($id);
$this->modal = $this->mapper->toDto($entity, ProfilePersonDto::class);
$this->respond();
}
...

and then send respond by json to client side.

After update data from client it send back to server:
...
/** @Action(url="/save", method="POST", 
requestBody="CMS\Dto\ProfilePersonDto") */
public function save(){
$entity = $this->mapper->toEntity($this->requestBody, 
ProfilePersonEntity::class);
$entity = $this->profilePersonService->save($entity, /* unlock */true);
$this->modal = $this->mapper->toDto($entity, ProfilePersonDto::class);
$this->respond();
}
...
requestBody that is the dto i'm mapping from rawdata (json) to
and then i'm mapping the dto object to the ProfilePersonEntity and call 
service to save

(save function in service)
protected function save($params) {
$entityClass = count($params) > 2 ? $params[2] : 
AnnotationUtil::getMappingClass(get_called_class());
$unlock = isset($params[1]) ? $params[1] : false; 
$entity = $params[0];
if (!is_null($entity)) {
try {
if (isset($this->currentUser)) {
if ($entity->getId()) {
$entity = $this->entityManager->merge($entity);   
 =============>>>>>>>>>>Problem from here

if (get_class($entity) === AccountEntity::class && 
is_null($entity->getPassword())) {
$originalEntity = 
$this->entityManager->getUnitOfWork()->getOriginalEntityData($entity);
$entity->setPassword($originalEntity['password']);
} elseif ($entity::hasBelongTo()) {
$entity->setBelongTo($this->belongTo);
}
}
else {
$this->entityManager->persist($entity);
}
$entity->setLockOwner($unlock ? NULL : $this->currentUser);
 $errors = $this->_validate($entity);
if (count($errors) > 0) {
throw new ValidationException($errors);
}
 $this->entityManager->flush();
}
else {
//TODO [HCN] Handle exception when save entity without login
}
}
catch (OptimisticLockException $ole) {
$entity = $this->entityManager->find($entityClass, $entity->getId());
throw new OptimisticLockException(I18n::t('validation.optimisticLock'), 
$entity);
}
}
return $entity;
}

The entity just merge all the fields of ProfilePersonEntity and another 
fields of parent class (ProfileEntity, ....), it do nothing (nothing merge, 
just original data)
That why after flush just all the fields of ProfilePersonEntity updated on 
DB.

Hope everyone help the fixed or explain what happen
Thank you.

Brian


On Wednesday, December 3, 2014 3:38:00 AM UTC+7, Marco Pivetta wrote:
>
> Hi Cuong,
>
> Could you please make an example of what is crashing? Did you also 
> validate your mappings?
>
> Marco Pivetta 
>
> http://twitter.com/Ocramius      
>
> http://ocramius.github.com/
>
> On 2 December 2014 at 17:20, Cuong Nguyen <[email protected] <javascript:>
> > wrote:
>
>> Hi everyone
>> I try top update the exists entity by using entity merge, with another 
>> normal entity everything fine, but when i create the entities 
>> with Inheritance type SINGLE_TABLE,
>> the entity merge just working with all the fields in mapper entity only, 
>> and all the parent class field cannot update. I'm already check the problem 
>> came from entity merge.
>>
>> Please check the code below, all the field in ProfilePersonEntity & 
>> ProfileCompanyEntity update after merge but all the field in ProfileEntity 
>> didn't update anything.
>> Somebody can help to know where the problem came from, doctrine or my 
>> code.
>>
>> Thank you very much...
>> Regards,
>> Brian
>>
>> ProfileEntity.php
>>
>> namespace CMS\Entity;
>>
>> use Doctrine\ORM\Mapping\Entity;
>> use Doctrine\ORM\Mapping\Table;
>> use Doctrine\ORM\Mapping\InheritanceType;
>> use Doctrine\ORM\Mapping\DiscriminatorColumn;
>> use Doctrine\ORM\Mapping\DiscriminatorMap;
>> use Doctrine\ORM\Mapping\Column;
>> use Doctrine\ORM\Mapping\OneToMany;
>> use Symfony\Component\Validator\Constraints as Assert;
>> use Doctrine\Common\Collections\ArrayCollection;
>>
>> /**
>>  * @Entity
>>  * @Table(name="PROFILE")
>>  * @InheritanceType("SINGLE_TABLE")
>>  * @DiscriminatorColumn(name="type", type="string")
>>  * @DiscriminatorMap({
>>  *     "Profile" = "ProfileEntity", 
>>  *     "ProfilePerson" = "ProfilePersonEntity",
>>  *     "ProfileCompany" = "ProfileCompanyEntity"
>>  * })
>>  */
>> class ProfileEntity extends LockableEntity {
>>
>> /**
>>  * @Column(name="TYPE", type="string", length=15)
>>  * @Assert\NotBlank
>>  */
>> private $type;
>>     /** 
>>      * @Column(name="NAME", type="string", length=45)
>>      * @Assert\NotBlank
>>      */
>>     private $name;
>>     
>>     /**
>>      * @Column(name="PLACE_OF_ISSUE", type="string", length=45)
>>      */
>>     private $placeOfIssue;
>>     
>>     /**
>>      * @Column(name="DATE_OF_ISSUE", type="timestamp")
>>      */
>>     private $dateOfIssue;
>>     
>>     /**
>>      * @Column(name="NATIONALITY", type="string", length=3)
>>      */
>>     private $nationality;
>>     
>>     /**
>>      * @OneToMany(targetEntity="PhoneEntity", mappedBy="profile", 
>> cascade={"all"})
>>      */
>>     private $phones;
>>     
>>     /**
>>      * @OneToMany(targetEntity="EmailEntity", mappedBy="profile", 
>> cascade={"all"})
>>      */
>>     private $emails;
>>     
>>     /**
>>      * @OneToMany(targetEntity="WebsiteEntity", mappedBy="profile", 
>> cascade={"all"})
>>      */
>>     private $websites;
>>     
>>     /**
>>      * @OneToMany(targetEntity="AddressProfileEntity", 
>> mappedBy="profile", cascade={"all"})
>>      */
>>     private $addresses;
>>     
>>     
>>     public function __construct() {
>>     $this->phones = new ArrayCollection();
>>     $this->emails = new ArrayCollection();
>>     $this->websites = new ArrayCollection();
>>     $this->addresses = new ArrayCollection();
>>     }
>>
>>     
>>     public function getType() {
>>     return $this->type;
>>     }
>>     public function setType($type) {
>>     $this->type = $type;
>>     }
>>     
>>     public function getName() {
>>         return $this->name;
>>     }
>>     public function setName($name) {
>>         $this->name = $name;
>>     }
>>     
>>     public function getPlaceOfIssue() {
>>     return $this->placeOfIssue;
>>     }
>>     public function setPlaceOfIssue($placeOfIssue) {
>>     $this->placeOfIssue = $placeOfIssue;
>>     }
>>     
>>     public function getDateOfIssue() {
>>     return $this->dateOfIssue;
>>     }
>>     public function setDateOfIssue($dateOfIssue) {
>>     $this->dateOfIssue = $dateOfIssue;
>>     }
>>     
>>     public function getNationality() {
>>     return $this->nationality;
>>     }
>>     public function setNationality($nationality) {
>>     $this->nationality = $nationality;
>>     }
>>     
>>     public function getPhones() {
>>     return $this->phones;
>>     }
>>     public function setPhones($phones) {
>>     $this->phones = $phones;
>>     }
>>     
>>     public function getEmails() {
>>     return $this->emails;
>>     }
>>     public function setEmails($emails) {
>>     $this->emails = $emails;
>>     }
>>     
>>     public function getWebsites() {
>>     return $this->websites;
>>     }
>>     public function setWebsites($websites) {
>>     $this->websites = $websites;
>>     }
>>     
>>     public function getAddresses() {
>>     return $this->addresses;
>>     }
>>     public function setAddresses($addresses) {
>>     $this->addresses = $addresses;
>>     }
>>     
>>     public function getFullname() {
>>     return (method_exists($this, 'getLastName') ? $this->getLastName().' 
>> ' : '').$this->name;
>>     }
>>
>> }
>>
>>
>> ==============================================================================================
>> ProfilePersonEntity.php
>>
>> namespace CMS\Entity;
>>
>> use Doctrine\ORM\Mapping\Entity;
>> use Doctrine\ORM\Mapping\Column;
>>
>> /**
>>  * @Entity
>>  */
>> class ProfilePersonEntity extends ProfileEntity {
>>
>> /**
>>  * @Column(name="LAST_NAME", type="string", length=45)
>>  */
>> private $lastName;
>>
>> /**
>>  * @Column(name="GENDER", type="string", length=9)
>>  */
>> private $gender;
>>
>> /**
>>  * @Column(name="BIRTHDAY", type="timestamp")
>>  */
>> private $birthday;
>>
>> /**
>>  * @Column(name="IDENTITY_NUMBER", type="string", length=45)
>>  */
>> private $identityNumber;
>>
>> /**
>>  * @Column(name="PASSPORT_NUMBER", type="string", length=45)
>>  */
>> private $passportNumber;
>>
>>
>> public function __construct() {}
>>
>>
>> public function getLastName() {
>> return $this->lastName;
>> }
>> public function setLastName($lastName) {
>> $this->lastName = $lastName;
>> }
>>
>> public function getGender() {
>> return $this->gender;
>> }
>> public function setGender($gender) {
>> $this->gender = $gender;
>> }
>>
>> public function getBirthday() {
>> return $this->birthday;
>> }
>> public function setBirthday($birthday) {
>> $this->birthday = $birthday;
>> }
>>
>> public function getIdentityNumber() {
>> return $this->identityNumber;
>> }
>> public function setIdentityNumber($identityNumber) {
>> $this->identityNumber = $identityNumber;
>> }
>>
>> public function getPassportNumber() {
>> return $this->passportNumber;
>> }
>> public function setPassportNumber($passportNumber) {
>> $this->passportNumber = $passportNumber;
>> }
>>
>> }
>>
>>
>> ==============================================================================================
>> ProfileCompanyEntity.php
>>
>> namespace CMS\Entity;
>>
>> use Doctrine\ORM\Mapping\Entity;
>> use Doctrine\ORM\Mapping\Column;
>>
>> /**
>>  * @Entity
>>  */
>> class ProfileCompanyEntity extends ProfileEntity {
>>
>> /**
>>  * @Column(name="ENGLISH_NAME", type="string", length=45)
>>  */
>> private $englishName;
>>
>> /**
>>  * @Column(name="TAX_CODE", type="string", length=45)
>>  */
>> private $taxCode;
>>
>> /**
>>  * @Column(name="BUSINESS_REGISTRATION_CODE", type="string", length=45)
>>  */
>> private $businessRegistrationCode;
>>
>>
>> public function __construct() {}
>>
>>
>> public function getEnglishName() {
>> return $this->englishName;
>> }
>> public function setEnglishName($englishName) {
>> $this->englishName = $englishName;
>> }
>>
>> public function getTaxCode() {
>> return $this->taxCode;
>> }
>> public function setTaxCode($taxCode) {
>> $this->taxCode = $taxCode;
>> }
>>
>> public function getBusinessRegistrationCode() {
>> return $this->businessRegistrationCode;
>> }
>> public function setBusinessRegistrationCode($businessRegistrationCode) {
>> $this->businessRegistrationCode = $businessRegistrationCode;
>> }
>>
>> }
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to