Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:48:41+00:00 2026-05-28T07:48:41+00:00

In my model I have Terrain.php /** * @ORM\Entity * @ORM\HasLifecycleCallbacks() */ class Terrain

  • 0

In my model I have

Terrain.php

/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class Terrain
{

 /**
  * @var lots
  *
  * @ORM\OneToMany(targetEntity="Lot", mappedBy="terrain")
  */
  private $lotes;

  /**
   * @ORM\PreRemove
   */
  public function deleteAllLots()
  {
    $lots = $this->getLots();

    foreach ($lots as $lot) {
        $this->lots->removeElement($lot);
    }
  }

}

Lot.php

/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class Lot
{

 /**
  * @var Terrain
  *
  * @ORM\ManyToOne(targetEntity="Terrain", inversedBy="lots")
  * @ORM\JoinColumns({
  *   @ORM\JoinColumn(name="terrain_id", referencedColumnName="id")
  * })
  */
  var $terrain

}

Lot

I’m trying to delete a terrain, but formerly i deleted all lots associated with it. when i try to delete a Terrain, i get an error SQLSTATE[23000]: Integrity constraint violation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:48:42+00:00Added an answer on May 28, 2026 at 7:48 am

    You still have a reference from lots to terrain on deleting, that’s why you have an Integrity constrait violation.

    Try this :

    /**
    * @ORM\Entity
    * @ORM\HasLifecycleCallbacks()
    */
    class Terrain
    {
        /**
        * @var lots
        *
        * @ORM\OneToMany(targetEntity="Lot", mappedBy="terrain")
        */
        private $lotes;
    
        /**
        * @ORM\PreRemove
        */
        public function deleteAllLots()
        {
            $lots = $this->getLots();
    
            foreach ($lots as $lot) {
                $this->lots->removeElement($lot);
                $lot->terrain = null; //$lot->setTerrain(null); will be better, try to add getters and setters
            }
        }
    }
    

    If you want to delete lots from database, you should use cascade property of OneToMany relation (One-To-Many reference on doctrine-project.com), like this :

    /**
    * @ORM\Entity
    * @ORM\HasLifecycleCallbacks()
    */
    class Terrain
    {
        /**
        * @var lots
        *
        * @ORM\OneToMany(targetEntity="Lot", mappedBy="terrain", cascade={"remove"})
        */
        private $lotes;
    }
    

    On Terrainremove, all lots will be removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my business model I have Entity class (IPoint interface ) that has a
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
Lets say I have model inheritance set up in the way defined below. class
in a Model I have a CharField with choices: class MyModel(models.Model): THE_CHOICES=( ('val',_(u'Value Description')),
I have created a Dynamic Data site against an Entity Framework Model I have
I have coded a 3d-terrain engine with simplistic model engine on top of it.
I have a polygon and a terrain model (can be either grid or TIN).
I have a lot of model classes with ralations between them with a CRUD
I have model: class Topic < ActiveRecord::Base attr_accessible :title, :description has_many :comments, :dependent =>
I have model class which contains NSString's- studentName , studentRank and studentImage . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.