php - foscommentbundle keeps creating new entries instead of saving the old one -
problem:
the foscommentbundle saves comments everytime refresh page, create new entry in thread table instead of saving on record page. example, if page slug http://johnson.localhost/app_dev.php/page/whats-up-baby, new record created everytime reresh page, table looks this:
notice slugs same! here's how expect work:
but refresh, starts creating new entries like:
i'm displaying form this:
{% include 'foscommentbundle:thread:async.html.twig' {'id': post.id} %}
and i'm using yaml, here thread , commment yaml files.
johnson\blogbundle\entity\thread: type: entity table: null id: id: type: integer id: true generator: strategy: auto lifecyclecallbacks: { } johnson\blogbundle\entity\comment: type: entity manytoone: thread: targetentity: johnson\blogbundle\entity\thread inversedby: comments table: null id: id: type: integer id: true generator: strategy: auto lifecyclecallbacks: { }
i don't know how represent:
* @orm\changetrackingpolicy("deferred_explicit")
in yaml. problem?
the problem facing not related changetrackingpolicy option. anyway if set value in yaml, can as:
changetrackingpolicy : deferred_explicit
now problem. seams value of provided post.id changing on each request. try put {{ post.id }} in template view value of it. should same unique identifier of post entity(assuming have post entity).
updated:
okk, yo mentioned, there no problem post id in short solution updating generator strategy in yaml thread entity like:
docudex\bundle\commentbundle\entity\thread: type: entity table: null id: id: type: integer id: true generator: strategy: none lifecyclecallbacks: { } changetrackingpolicy : deferred_explicit
make sure clear wrong thread entry first, clear cache. hope solve problem.
explanation:
when set generator strategy auto, doctrine setting new auto generated id new thread. though not suppose happen, happening! found if create entities within child bundle of foscommentbundle auto strategy doesn't have problem. that's why, when tried first time gave me no problem. able reproduce problem in environment moving entities out of child bundle.
suggestion:
though simple setup, can go approach, idea create child bundle when use bundles these. give more power customize.
Comments
Post a Comment