私は2つのエンティティを持っています。一つは、識別器などで構成されるメインのスーパークラスとして、もう一つはスーパークラスを継承しています... アクションと呼ばれる1つのテーブル。Doctrine 2 Discriminator継承マッピングはfindByメソッドが動作しないことにつながります
私discrimatorエンティティ:
namespace Entities\Members;
/**
* @Entity
* @Table(name="actions")
* @MappedSuperClass
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="action_type", type="string")
* @DiscriminatorMap({"comments" = "Comments", "blog" = "Blog"})
* @HasLifecycleCallbacksIndex
*/
class Action {
/**
* @Id
* @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @Column(type="string", length=300, nullable=true) */
public $name;
/** @Column(name="action_date", type="datetime", columnDefinition="datetime", nullable=false) */
protected $action_date;
/** @PrePersist */
public function updated() {
$this->action_date = new \DateTime("now");
}
}
これは私が上記discrimatorエンティティを拡張するために使用私のエンティティのいずれかになります。
namespace Entities\Members;
/**
* @Entity
* @Table(name="comments")
* @HasLifecycleCallbacks
*/
class Comments extends Action {
/**
* @Id @Column(name="id", type="bigint",length=15)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @Column(name="blog_id", type="integer", nullable=true) */
protected $blog_id;
/** @Column(name="comment", type="string", length=255, nullable=true) */
protected $comment;
/** @Column(name="comment_date", type="datetime", columnDefinition="datetime", nullable=true) */
protected $comment_date;
/**
* @ManyToOne(targetEntity="Members",inversedBy="comments", cascade={"persist"})
* @JoinColumn(name="userid", referencedColumnName="id")
*/
protected $author;
public function __construct() {
$this->comment_date = $this->comment_date = new \DateTime("now");
}
}
私はコメントエンティティを永続化するとき、これは例えば、うまく動作します
$entity = new Entities\Comments;
$entity->comment = "my new comment";
$this->em->persist($entity);
$this->em->flush();
私が持続する場合、それがアクションテーブルに成功したアクションが追加されます...
しかし、私は= ,,もはやこれらのメソッドからのすべての結果の戻り値を任意のfindBy、findByOneメソッドを使用することはできませんnull コメントクラスを編集して 'アクションからの延長'を削除すると、doctrine findby、findOneByメソッドが動作を開始します しかし、それはメインアクションスーパークラスを拡張しないので、tmyディスクリミネータテーブルに追加されません...
私はアクションを拡張し、doctrineメソッドをsuにする必要がありますchを見つける、findOneBy、等も...
どのような提案?
いいえ.. get_class($ entity)を実行すると、このコードが実際のクラス名を出力します。BaseController?しかし、私は '拡張アクティビティ'を削除する場合は、エンティティ/コメントを出力するので、アクションを拡張しないとうまくいきます。 –
あなたの質問コードを投稿してください。 – Cerad
あなたと同じ:$ repo = $ this - > _ em-> getRepository( 'Entities \ Comments'); $ entity = $ repo-> findOneBy(array( 'name' => 'bars')); // $ entity = $ repo-> findOneById(233); echo get_class($ entity)。 ''。 $ entity-> id。 "\ n";あなたが上に見ることができるように私は両方を試みた... findOneByIdとfindOneBy(配列)私はそのIDがそれを拡張しているすべてのエンティティと衝突していると思う....(アクションidフィールド) –