Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine Cascade Options for OneToMany
    primarykey
    data
    text
    <p>I'm having a hard time making sense of the Doctrine manual's <a href="http://www.doctrine-project.org/docs/orm/2.1/en/reference/working-with-associations.html#transitive-persistence-cascade-operations" rel="noreferrer">explanation</a> of cascade operations and need someone to help me understand the options in terms of a simple ManyToOne relationship.</p> <p>In my application, I have a table/entity named Article that has a foreign key field referencing the 'id' field in a table/entity named Topic.</p> <p>When I create a new Article, I select the Topic from a dropdown menu. This inserts an integer into the 'topic_id' foreign key field in the Article table.</p> <p>I have the $topic association set up in the Article entity like this:</p> <pre><code>/** * @ManyToOne(targetEntity="Topic") * @JoinColumn(name="topic_id", referencedColumnName="id", nullable=false) */ private $topic; </code></pre> <p>The Topic entity doesn't have any reciprocating annotation regarding the Article entity. Topics don't care what Articles reference them and nothing needs to happen to a Topic when an Article that references the Topic is deleted.</p> <p>Because I'm not specifying the cascade operation in the Article entity, Doctrine throws an error when I try to create a new Article: "A new entity was found through a relationship that was not configured to cascade persist operations. Explicitly persist the new entity or configure cascading persist operations on the relationship."</p> <p>So I know I need to choose a cascade operation to include in the Article entity, but how do I know which operation to choose in this situation?</p> <p>From reading the Doctrine manual, "detach" sounds like the right option. But researching others' similar questions <a href="https://stackoverflow.com/questions/7467982/error-saving-onetomany-and-manytomany-relationship-with-doctrine-2">here</a> and <a href="https://stackoverflow.com/questions/7467982/error-saving-onetomany-and-manytomany-relationship-with-doctrine-2">here</a> makes me think I want to use "persist" instead.</p> <p>Can anyone help me understand what "persist," "remove," "merge," and "detach" mean in terms of a simple ManyToOne relationship like the one I've described?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload