-
27-09-2019 - |
質問
いコンクリートのサンプルコード主義2を使用する"多様な組合".私の解明です。私はエンティティという契約は、契約できる多くの価格規則およびこれらの価格規則である必要はありませんのような授業やpresisted異なる。と思い、この多型に関連付けられたすべてのは私が悪いのでしょうか。
class contract {
private $id;
private $priceRules;
}
class discountRule implements priceRule{
function calculate() {
// calculate new price after this rule
}
}
class extraSpecialRule implements priceRule {
function calculate() {
// calculate new price after this rule
}
}
ができる新しいタイプの価格規則では、今後も、たいのですが准教授にこれらのルールを主体とpresistして別のテーブル?
更新:
これが私の新しいコード:
contract.php
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity @Table(name="contract")
*/
class Contract {
/**
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @Column(type="integer")
*/
private $propertyId;
/**
*
* @Column(type="integer")
*/
private $agencyId;
/**
*
* @OneToMany(targetEntity="priceRule" ,mappedBy="contract")
*
*/
private $priceRules;
public function __construct($propertyId,$agencyId){
$this->propertyId=$propertyId;
$this->agencyId=$agencyId;
$this->priceRules=new ArrayCollection();
}
public function addPriceRule(priceRule $rule){
$this->priceRules[]=$rule;
}
public function getPriceRules(){
return $this->priceRules;
}
}
pricerule.php
namespace Entities;
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr" , type="string")
* @DiscriminatorMap({"discountrule"="discountRule","extradiscountrule"="extraDiscountRule"})
*/
class priceRule{
/**
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @ManyToOne(targetEntity="contract",inversedBy="availibilityRules")
* @JoinColumn("contract_id",referencedColumnName="id")
*/
private $contract;
}
discountrule.php
namespace Entities;
/**
* @Entity
*
*
*/
class discountRule extends priceRule {
/**
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
public function calculatePrice(){
// calculate new price
}
}
extradiscountrule.php
namespace Entities;
/**
* @Entity
*
*
*/
class extraDiscountRule extends priceRule {
/**
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
public function calculate() {
// calculate new price
}
}
sampleusage.php
$contract=new Contract(1,1);
$discount=new discountRule();
$em->persist($discount);
$contract->addPriceRule($discount);
$em->persist($contract->getPriceRules());
$em->persist($contract);
$em->flush();
そうして新しいルールの契約を取得しますエラーメッセージの致命的なエラー:キャッチされない例外'義\ORM\ンマッピング\MappingException'メッセージ種主義\Common\集\ArrayCollectionは有効なエンティティをマップスーパークラスです。)
なぜですか?
解決
すが、@MappedSuperclassおPriceRule親オブジェクト
参照: 相続マッピング
他のヒント
ないことが可能でのインタフェースにより定性クラスでできない保証はありますの性質主義を操作する.
をご提供いただければより詳細を主体でも貢献できたことがります。
所属していません StackOverflow