OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – How do I? Questions Form remove one-to-many entities

This topic contains 4 replies, has 2 voices, and was last updated by  Anonymous 9 years, 8 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #35786

    Anonymous

    Hi,
    I have created a form with a collection of another entity (Question with Answers). I think is similar to Contacts and Address entities in Orocrm.

    The problem is that I’m not be able to “delete” answers (only add). The relation is OneToMany (question -> answer) and I read in the symfony book that this operation is not automatically accomplished by doctrine.

    Where in the orocrm code this operation is performed? I have missed anything?

    Best regards and excuse me for the very bad english,

    Carlo

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #35787

    Alexandr Smaga
    Participant

    Hello. Yes I think you missed orphan removal (see). This options requires doctrine to check if entity that has been extracted as a part of collection and now detached from it then it should be removed as orphan.

    #35788

    Anonymous

    Hi Alexandr, thank you for the answer.

    I already have “orphanRemoval” but the problem persist. This is my entity Question:

    /**
    * @var Collection
    * @ORM\OneToMany(targetEntity=”Answer”,
    * mappedBy=”question”, orphanRemoval=true
    * )
    */
    private $answers;

    but if I post a form without answers, these are not deleted from DB. Have I missed something?

    C.

    #35789

    Alexandr Smaga
    Participant

    Do you have method removeAnswer ?

    It should looks like this

    #35790

    Anonymous

    Yes, this function (togheter with addAnswer(), getAnswer(), and setAnswer() plus __construct()) is generated by doctrine automagically based on yaml file configuration.

Viewing 4 replies - 1 through 4 (of 4 total)

The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.

Back to top