必须对实体进行管理或计划以删除Symfony/Twig中的单个计算



当我尝试使用delete or clear快递公司时,它会在错误后抛出。我认为我没有良好的调试技能。有人可以帮助我,这背后的原因是什么?这是控制器,视图和模态。

 Entity has to be managed or scheduled for removal for single computation SokosimuPostalDeliveryBundleEntityPostalCharge@0000000059f7113c00000000372b1d9d

控制器

 public function clearRatesAction(DeliveryCompany $deliveryCompany){
    $em = $this->get('doctrine')->getManager();
    $postalcharge = new PostalCharge();
    $em->getConnection()->beginTransaction();
    try {
        $rate = $postalcharge ->setDeliveryCompany($deliveryCompany);
        $em->persist($rate);
        $em->remove($rate);
        $em->flush($rate);
        $em->getConnection()->commit();
    }  catch(Exception $e){
        $em->getConnection()->rollback();
        throw $e;
    }
    return $this->redirect($this->generateUrl('sokosimu_postal_delivery_list_company'));
}
}

twig(views)

<tbody>
   {% for deliveryCompany in deliveryCompanyList %}
     <tr>
    <td><a href="{{ path('sokosimu_postal_delivery_company_detail',{'deliveryCompany':deliveryCompany.getid()}) }}">{{ deliveryCompany.getName() }}</td>
<td>{{ deliveryCompany.getAddress() }}</td>
 <td><a href="{{ path('sokosimu_postal_delivery_company_edit',{'deliveryCompany':deliveryCompany.getId()}) }}">Edit</a>
 <a href="{{ path('sokosimu_postal_delivery_clear_rates',{'deliveryCompany':deliveryCompany.getId()}) }}">ClearRates</a>
                                </td>
                            </tr>
 {% endfor %}
 </tbody>

邮政费用实体

     <?php
    // src/Sokosimu/PostalDeliveryBundle/Entity/PostalCharge.php
    namespace SokosimuPostalDeliveryBundleEntity;
    use DoctrineORMMapping as ORM;
    /**  *                 @ORMEntity(repositoryClass="SokosimuPostalDeliveryBundleEntityRepositoryPostalChargeRepository")
  * @ORMTable(name="postal_charge")
  * @ORMHasLifecycleCallbacks()
  */
class PostalCharge
{
/**
 * @ORMId
 * @ORMColumn(name="id",type="integer")
 * @ORMGeneratedValue(strategy="AUTO")
 */
protected $id;
/**
 * @ORMColumn(name="record_type",type="string", length=225)
 */
protected $recordType;
/**
 * @ORMColumn(name="active_from",type="datetime",  nullable=True)
 */
protected $activeFrom;
/**
 * @ORMColumn(name="active_to",type="datetime",  nullable=True)
 */
protected $activeTo;
/**
 * @ORMColumn(name="active_record",type="string", length=225, nullable=True)
 */
protected $activeRecord;
/**
 * @ORMColumn(name="origin_country",type="string", length=225, nullable=True)
 */
protected $originCountry;
/**
 * @ORMColumn(name="weight_from",type="integer")
 */
protected $weightFrom;
/**
 * @ORMColumn(name="weight_to",type="integer")
 */
protected $weightTo;
/**
 * @ORMColumn(name="from_region",type="string", length=225, nullable=True)
 */
protected $fromRegion;
/**
 * @ORMColumn(name="to_region",type="string", length=225, nullable=True)
 */
protected $toRegion;
/**
 * @ORMColumn(name="priority",type="string", length=225, nullable=True)
 */
protected $priority;
/**
 * @ORMColumn(name="economy",type="string", length=225, nullable=True)
 */
protected $economy;
/**
 * @ORMColumn(name="increment_price",type="string", length=225, nullable=True)
 */
protected $incrementPrice;
/**
 * @ORMColumn(name="tax",type="string", length=225, nullable=True)
 */
protected $tax;
/**
 * @ORMColumn(name="insurance",type="string", length=225, nullable=True)
 */
protected $insurance;
/**
 * @ORMColumn(name="increment_unit",type="string", length=225, nullable=True)
 */
protected $incrementUnit;

/**
 * @ORMColumn(name="currency_code",type="string", length=225, nullable=True)
 */
protected $currencyCode;
/**
 * @ORMColumn(name="country_code",type="string", length=225, nullable=True)
 */
protected $countryCode;
/**
 * @ORMManyToOne(targetEntity="DeliveryCompany")
 * @ORMJoinColumn(name="delivery_company_id",referencedColumnName="id",nullable=True)
 */
protected $deliveryCompany;

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}
/**
 * Set recordType
 *
 * @param string $recordType
 * @return PostalCharge
 */
public function setRecordType($recordType)
{
    $this->recordType = $recordType;
    return $this;
}
/**
 * Get recordType
 *
 * @return string 
 */
public function getRecordType()
{
    return $this->recordType;
}
/**
 * Set activeFrom
 *
 * @param DateTime $activeFrom
 * @return PostalCharge
 */
public function setActiveFrom($activeFrom)
{
    $this->activeFrom = $activeFrom;
    return $this;
}
/**
 * Get activeFrom
 *
 * @return DateTime 
 */
public function getActiveFrom()
{
    return $this->activeFrom;
}
/**
 * Set activeTo
 *
 * @param DateTime $activeTo
 * @return PostalCharge
 */
public function setActiveTo($activeTo)
{
    $this->activeTo = $activeTo;
    return $this;
}
/**
 * Get activeTo
 *
 * @return DateTime 
 */
public function getActiveTo()
{
    return $this->activeTo;
}
/**
 * Set activeRecord
 *
 * @param string $activeRecord
 * @return PostalCharge
 */
public function setActiveRecord($activeRecord)
{
    $this->activeRecord = $activeRecord;
    return $this;
}
/**
 * Get activeRecord
 *
 * @return string 
 */
public function getActiveRecord()
{
    return $this->activeRecord;
}
/**
 * Set originCountry
 *
 * @param string $originCountry
 * @return PostalCharge
 */
public function setOriginCountry($originCountry)
{
    $this->originCountry = $originCountry;
    return $this;
}
/**
 * Get originCountry
 *
 * @return string 
 */
public function getOriginCountry()
{
    return $this->originCountry;
}
/**
 * Set weightFrom
 *
 * @param integer $weightFrom
 * @return PostalCharge
 */
public function setWeightFrom($weightFrom)
{
    $this->weightFrom = $weightFrom;
    return $this;
}
/**
 * Get weightFrom
 *
 * @return integer 
 */
public function getWeightFrom()
{
    return $this->weightFrom;
}
/**
 * Set weightTo
 *
 * @param integer $weightTo
 * @return PostalCharge
 */
public function setWeightTo($weightTo)
{
    $this->weightTo = $weightTo;
    return $this;
}
/**
 * Get weightTo
 *
 * @return integer 
 */
public function getWeightTo()
{
    return $this->weightTo;
}
/**
 * Set fromRegion
 *
 * @param string $fromRegion
 * @return PostalCharge
 */
public function setFromRegion($fromRegion)
{
    $this->fromRegion = $fromRegion;
    return $this;
}
/**
 * Get fromRegion
 *
 * @return string 
 */
public function getFromRegion()
{
    return $this->fromRegion;
}
/**
 * Set toRegion
 *
 * @param string $toRegion
 * @return PostalCharge
 */
public function setToRegion($toRegion)
{
    $this->toRegion = $toRegion;
    return $this;
}
/**
 * Get toRegion
 *
 * @return string 
 */
public function getToRegion()
{
    return $this->toRegion;
}
/**
 * Set priority
 *
 * @param string $priority
 * @return PostalCharge
 */
public function setPriority($priority)
{
    $this->priority = $priority;
    return $this;
}
/**
 * Get priority
 *
 * @return string 
 */
public function getPriority()
{
    return $this->priority;
}
/**
 * Set economy
 *
 * @param string $economy
 * @return PostalCharge
 */
public function setEconomy($economy)
{
    $this->economy = $economy;
    return $this;
}
/**
 * Get economy
 *
 * @return string 
 */
public function getEconomy()
{
    return $this->economy;
}
/**
 * Set incrementPrice
 *
 * @param string $incrementPrice
 * @return PostalCharge
 */
public function setIncrementPrice($incrementPrice)
{
    $this->incrementPrice = $incrementPrice;
    return $this;
}
/**
 * Get incrementPrice
 *
 * @return string 
 */
public function getIncrementPrice()
{
    return $this->incrementPrice;
}
/**
 * Set tax
 *
 * @param string $tax
 * @return PostalCharge
 */
public function setTax($tax)
{
    $this->tax = $tax;
    return $this;
}
/**
 * Get tax
 *
 * @return string 
 */
public function getTax()
{
    return $this->tax;
}
/**
 * Set insurance
 *
 * @param string $insurance
 * @return PostalCharge
 */
public function setInsurance($insurance)
{
    $this->insurance = $insurance;
    return $this;
}
/**
 * Get insurance
 *
 * @return string 
 */
public function getInsurance()
{
    return $this->insurance;
}
/**
 * Set incrementUnit
 *
 * @param string $incrementUnit
 * @return PostalCharge
 */
public function setIncrementUnit($incrementUnit)
{
    $this->incrementUnit = $incrementUnit;
    return $this;
}
/**
 * Get incrementUnit
 *
 * @return string 
 */
public function getIncrementUnit()
{
    return $this->incrementUnit;
}
/**
 * Set currencyCode
 *
 * @param string $currencyCode
 * @return PostalCharge
 */
public function setCurrencyCode($currencyCode)
{
    $this->currencyCode = $currencyCode;
    return $this;
}
/**
 * Get currencyCode
 *
 * @return string 
 */
public function getCurrencyCode()
{
    return $this->currencyCode;
}
/**
 * Set countryCode
 *
 * @param string $countryCode
 * @return PostalCharge
 */
public function setCountryCode($countryCode)
{
    $this->countryCode = $countryCode;
    return $this;
}
/**
 * Get countryCode
 *
 * @return string 
 */
public function getCountryCode()
{
    return $this->countryCode;
}
/**
 * Set deliveryCompany
 *
 * @param SokosimuPostalDeliveryBundleEntityDeliveryCompany $deliveryCompany
 * @return PostalCharge
 */
public function setDeliveryCompany(SokosimuPostalDeliveryBundleEntityDeliveryCompany $deliveryCompany = null)
{
    $this->deliveryCompany = $deliveryCompany;
    return $this;
}
/**
 * Get deliveryCompany
 *
 * @return SokosimuPostalDeliveryBundleEntityDeliveryCompany 
 */
public function getDeliveryCompany()
{
    return $this->deliveryCompany;
}
}

据我了解,您要删除您的送货公司的每一个邮递。您似乎缺乏关于学说对象表示的基本知识,我建议您阅读和理解文档(特别是OneTomany部分):http://symfony.com/doc/current/doctrine.html

但是,这就是您应该做的:

 public function clearRatesAction(DeliveryCompany $deliveryCompany){
$em = $this->get('doctrine')->getManager();
$em->getConnection()->beginTransaction();
try {
    foreach($deliveryCompany->getRates() as $postalCharge) {
       $em->remove($postalCharge);
    }
    $em->flush( );
    $em->getConnection()->commit();
}  catch(Exception $e){
    $em->getConnection()->rollback();
    throw $e;
}

最新更新