別のテーブルのフィールドが更新されたときに、テーブルの複数の行で同じ値を更新しようとしています。問題は、必要なフィールドを変更するために、更新する複数の行を含むテーブルの行を誰が取得するかわからないことです。これを行う簡単な方法はありますか?更新する複数の行を含む表 table には、ID 値自体がありません。キー値としていくつかのフィールドがあり、それらの値は一意ではありません。
更新する行がいくつかあるテーブル:
/**
* @ORM\Entity
* @ORM\Table(name="catalog_has_prize")
* @Gedmo\Loggable
*/
class CatalogHasPrize
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Catalog", inversedBy="catalog_has_prize")
* @ORM\JoinColumn(name="catalog", referencedColumnName="id")
* @Gedmo\Versioned
*/
private $catalog;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Prizes\PrizesBundle\Entity\Prize", inversedBy="catalog_has_prize")
* @ORM\JoinColumn(name="prize", referencedColumnName="id")
* @Gedmo\Versioned
*/
private $prize;
/**
* @ORM\Column(type="float", nullable=false)
* @Gedmo\Versioned
*/
private $point_value;
/**
* @ORM\Column(type="float", nullable=false)
* @Gedmo\Versioned
*/
private $fullfillment_fee;
/**
* @ORM\Column(type="float", nullable=false)
* @Gedmo\Versioned
*/
private $margin;
/**
* @ORM\Column(type="integer", nullable=false)
* @Gedmo\Versioned
*/
private $points;
/**
* @ORM\Column(type="integer", nullable=false)
* @Gedmo\Versioned
*/
private $auto_calculated_points;
/**
* @ORM\Column(type="integer", nullable=false)
* @Gedmo\Versioned
*/
private $treshhold;
/**
* @ORM\ManyToOne(targetEntity="Prizes\PrizesBundle\Entity\Company", inversedBy="catalog_has_prize")
* @ORM\JoinColumn(name="company", referencedColumnName="id")
* @Gedmo\Versioned
*/
private $company;
/**
* @ORM\ManyToOne(targetEntity="Optime\AppStatusBundle\Entity\Status")
* @ORM\JoinColumn(name="status", referencedColumnName="id")
* @Gedmo\Versioned
*/
private $status;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $modified;
public function __construct( )
{
}
public function setPrize( $prize )
{
$this->prize = $prize;
}
public function getPrize( )
{
return $this->prize;
}
public function setCatalog( $catalog )
{
$this->catalog = $catalog;
}
public function getCatalog( )
{
return $this->catalog;
}
public function setCompany( $company )
{
$this->company = $company;
}
public function getCompany( )
{
return $this->company;
}
public function setStatus( $status )
{
$this->status = $status;
}
public function getStatus( )
{
return $this->status;
}
public function setPointValue( $point_value )
{
$this->point_value = $point_value;
}
public function getPointValue( )
{
return $this->point_value;
}
public function setFullfillmentFee( $fullfillment_fee )
{
$this->fullfillment_fee = $fullfillment_fee;
}
public function getFullfillmentFee( )
{
return $this->fullfillment_fee;
}
public function setMargin( $margin )
{
$this->margin = $margin;
}
public function getMargin( )
{
return $this->margin;
}
public function setPoints( $points )
{
$this->points = $points;
}
public function getPoints( )
{
return $this->points;
}
public function setAutoCalculatedPoints( $points )
{
$this->auto_calculated_points = $points;
}
public function getAutoCalculatedPoints( )
{
return $this->auto_calculated_points;
}
public function setTreshhold( $treshhold )
{
$this->treshhold = $treshhold;
}
public function getTreshhold( )
{
return $this->treshhold;
}
public function getCreated( )
{
return $this->created->format( 'd/m/Y' );
}
public function getModified( )
{
return $this->modified->format( 'd/m/Y' );
}
更新された値を保持するテーブル:
/**
* @ORM\Entity @ORM\Table(name="prize")
* @Gedmo\Loggable
*/
class Prize
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Gedmo\Versioned
*/
private $id;
/**
* @ORM\Column(type="string", length=170, nullable=false)
* @Gedmo\Translatable
* @Gedmo\Versioned
*/
private $name;
/**
* @ORM\Column(type="string", length=400, nullable=false)
* @Gedmo\Translatable
* @Gedmo\Versioned
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=false)
* @Gedmo\Versioned
*/
private $img;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $thumb;
/**
* @ORM\ManyToOne(targetEntity="Optime\AppStatusBundle\Entity\Status", cascade={""})
* @ORM\JoinColumn(name="status", referencedColumnName="id", onDelete="RESTRICT", onUpdate="CASCADE")
* @Gedmo\Versioned
*/
private $status;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $modified;
/**
* @ORM\OneToMany(targetEntity="CompanyCountryPrize", mappedBy="prize")
*/
private $company_country_prizes;
/**
* @ORM\ManyToMany(targetEntity="Category")
* @ORM\JoinTable(name="prize_has_category",
* joinColumns={@ORM\JoinColumn(name="prize", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category", referencedColumnName="id")}
* )
*/
private $categories;
/**
* @ORM\ManyToMany(targetEntity="Brand")
* @ORM\JoinTable(name="prize_has_brand",
* joinColumns={@ORM\JoinColumn(name="prize", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="brand", referencedColumnName="id")}
* )
*/
private $brands;
/**
* @ORM\OneToMany(targetEntity="Prizes\CatalogBundle\Entity\CatalogHasPrize", mappedBy="catalog")
*/
private $catalog_has_prize;
/**
* @ORM\OneToMany(targetEntity="PrizeMarketInfo", mappedBy="prize")
*/
private $market_infos;
/**
* @ORM\OneToMany(targetEntity="PurchasePrize", mappedBy="prize")
*/
private $purchase;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
public function __construct( )
{
$this->company_country_prizes = new \Doctrine\Common\Collections\ArrayCollection( );
$this->categories = new \Doctrine\Common\Collections\ArrayCollection( );
$this->brands = new \Doctrine\Common\Collections\ArrayCollection( );
$this->catalog_has_prize = new \Doctrine\Common\Collections\ArrayCollection( );
$this->market_infos = new \Doctrine\Common\Collections\ArrayCollection( );
}
public function getId( )
{
return $this->id;
}
public function setImg( $img )
{
if ( substr( $img, -4, 1 ) == "." )
$this->img = $img;
}
public function getImg( )
{
return $this->img;
}
public function setName( $name )
{
$this->name = $name;
}
public function getName( )
{
return $this->name;
}
public function setDescription( $description )
{
$this->description = $description;
}
public function getDescription( )
{
return $this->description;
}
public function setThumb( $thumb )
{
if ( substr( $thumb, -4, 1 ) == "." )
$this->thumb = $thumb;
}
public function getThumb( )
{
return $this->thumb;
}
public function setStatus( \Optime\AppStatusBundle\Entity\Status $status )
{
$this->status = $status;
}
public function getStatus( )
{
return $this->status;
}
public function getCreated( )
{
return $this->created;
}
public function getModified( )
{
return $this->modified;
}
public function setCompanyCountryPrize( \Prizes\PrizesBundle\Entity\CompanyCountryPrize $company_country_prizes )
{
$this->company_country_prizes[] = $company_country_prizes;
}
public function getCompanyCountryPrize( )
{
return $this->company_country_prizes;
}
public function setCategory( \Prizes\PrizesBundle\Entity\Category $categories )
{
$this->categories[] = $categories;
}
public function getCategory( )
{
return $this->categories;
}
public function setBrand( \Prizes\PrizesBundle\Entity\Brand $brands )
{
$this->brands[] = $brands;
}
public function getBrand( )
{
return $this->brands;
}
public function setCatalogHasPrize( \Prizes\CatalogBundle\Entity\CatalogHasPrize $catalog_has_prize )
{
$this->catalog_has_prize[] = $catalog_has_prize;
}
public function getCatalogHasPrize( )
{
return $this->catalog_has_prize;
}
public function setMarketInfo( \Prizes\PrizesBundle\Entity\PrizeMarketInfo $market_infos )
{
$this->market_infos[] = $market_infos;
}
public function getMarketInfo( )
{
return $this->market_infos;
}
public function getPurchase( )
{
return $this->purchase;
}
イベントリスナーを実行しようとする私の試み:
class DeactivatePrizesInCatalog {
public function postUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
if ($entity instanceof Prize) {
if ($entity->getStatus()->getName() == "Inactive"){
$catalogs = $entityManager->getRepository('CatalogBundle:CatalogHasPrize')->findBy(array('prize' => $entity->getId(),'status' => 7));
}
}
}
}
私の問題は、行を取得する方法がわからず、行を更新する方法がはるかにわからないことです。どんな助けでも大歓迎です。