1

次の状況:

親:

namespace Base;

/** @Entity @Table(name="section") */
class Section extends Skeleton {
/** 
 * @Id @Column(type="integer") 
 * @GeneratedValue(strategy="AUTO")
 */
protected $id;

/** @Column(length=256) */
protected $title;

/** @Column(length=256) */
protected $stylesheet;
}

子:

namespace Base2;

use \Base\Section AS BaseSection;

/** @Entity @Table(name="tbl_section") */
class Section extends BaseSection {
/**
 * @Id @Column(type="integer")
 * @GeneratedValue(strategy="AUTO")
 */
protected $id;

/** @Column(length=256) */
protected $title;

/** @Column(length=256) */
protected $stylesheet;
}

データベースからセクションを取得しようとすると、エラーがスローされます。

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.id' 
in 'where clause' in /var/www/eage_new_zf/library/Doctrine/DBAL/Connection.php 
on line 567 Call Stack #TimeMemoryFunctionLocation 10.0004489704{main}( 
)../index.php:0 20.03193296632Zend_Controller_Front->dispatch( ???, ??? 
)../index.php:27 30.04574505172Zend_Controller_Dispatcher_Standard->dispatch( 
object(Zend_Controller_Request_Http)[39], object(Zend_Controller_Response_Http)[40] 
)../Front.php:954 Variables in local scope (#3) 

実行しようとするクエリは次のとおりです。

SELECT 
    t1.id AS id2, 
    t1.title AS title3, 
    t1.stylesheet AS stylesheet4 
FROM 
    tbl_section t1 
WHERE 
    t0.id = ?

t0 は定義されていないため、技術的には正しいのですが、エラーが発生します。しかし、これを解決する方法は?Doctrine 2 のバグですか? それとも私は何か間違ったことをしていますか?

4

1 に答える 1

2

単一テーブルまたは結合テーブル継承のいずれかを使用できます。違いは、NULL 可能な列を持つ 1 つのテーブルを使用するか、子クラスに応じて多数のテーブルを使用するかです。mroe 情報については、マニュアルを参照してください。

http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/inheritance-mapping.html

あなたの場合、最上位/ルートクラス(Base\Section)

/**
 * @Entity @Table(name="section")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"base" = "Base\Section", "child" = "Base2\Section"})
 */

クラスに名前を付けるのは悪い習慣ですが、実装に関してクラスに名前を付ける必要があります。名前空間に既に含まれている単語、つまり例の Base\BaseSection と BAse2\Base2Section が重複している場合でも。

于 2010-08-10T19:54:22.637 に答える