symfony - Use Doctrine to merge entity with different subclass -


i have mapped superclass abstractquestion single-table-inheritance.

/**  * @orm\entity  * @orm\mappedsuperclass  * @orm\table(name="question")  * @orm\inheritancetype("single_table")  * @orm\discriminatorcolumn(name="dtype", type="string")  * @orm\discriminatormap({  *  "simple":   "simplequestion",  *  "dropdown": "dropdownquestion"  * })  */ abstract class abstractquestion 

simplequestion , dropdownquestion inherit superclass.

/**  * class simplequestion.  * @orm\entity()  */ class simplequestion extends abstractquestion 

i want modify existing simplequestion , make dropdownquestion.

when saving question, deserialise , merge question, contains id , 'dtype' , other properties.

$dquestion = $this->serial->fromjson($request->getcontent(), abstractquestion::class); $question = $this->em->merge($dquestion); $this->em->flush(); 

so submit like:

{ id: 12, dtype: 'dropdown', 'text': 'what favourite animal?'} 

after deserialisation, $dquestion dropdownquestion object desired, after merge $question simplequestion object in database previously, unique properties of dropdownquestion lost , question saved simplequestion. there way work around this?

you first have delete existing record (simplequestion) , insert new record (dropdownquestion). type casting not supported in doctrine 2.


note.
can change discriminator column pure sql query, is absolutely not recommended , sure give problems...

check answers here , here since might interesting you.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -