Skip to content

Instantly share code, notes, and snippets.

@boutell
Created July 26, 2012 17:06
Show Gist options
  • Save boutell/3183250 to your computer and use it in GitHub Desktop.
Save boutell/3183250 to your computer and use it in GitHub Desktop.
Deleting search objects related many-to-one to a given posting
// In my Search entity class:
/**
* @ORM\ManyToOne(targetEntity="Posting", inversedBy="words")
* @ORM\JoinColumn(name="posting_id", referencedColumnName="id", onDelete="cascade")
*/
protected $posting;
// Later, when I want to delete the Search objects for a given Posting entity:
foreach ($entity->getWords() as $search)
{
$em->persist($search);
$em->remove($search);
}
// This produces:
A new entity was found through the relationship 'Duke\DukeListBundle\Entity\Posting#words' that was not configured to cascade persist operations for entity: Duke\DukeListBundle\Entity\Search@000000003fbc63ae000000000717a61e. Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Duke\DukeListBundle\Entity\Search#__toString()' to get a clue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment