Doctrineは、新しいUserオブジェクトをインスタンス化するたびにすべてのプロパティをロードできるように、各情報の場所を教えておく必要があります。つまり、カスタムDoctrineマッピング情報を追加する必要があります。インライン注釈としてマッピング情報をユーザーのモデルクラスに追加するとしたら、コードは次のようになります。
//in User.php
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="first_table_name")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $username;
/**
* @ORM\OneToMany(targetEntity="UserStats")
*/
protected $stats;
//also define getters and setters for the above, of course
}
//in UserStats.php
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="table_two_name")
*/
class UserStats
{
/**
* I'm pretty sure doctrine will require that you add an Id column to table_two,
* which is what this is. If you can't add an Id, I'm not sure it'll work...
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
/**
* The below assumes your stats are strings. If not, change the type attribute.
* @ORM\Column(type="string")
*/
protected $stat1;
/**
* @ORM\Column(type="string")
*/
protected $stat2;
/**
* @ORM\Column(type="string")
*/
protected $stat3;
//include appropriate getters/setters here too
}
「保護された$統計情報」を追加しません。ユーザーエンティティに試してそのテーブルに列を追加しますか? – chasen
あなたにそれを伝えない限り。 D2はデータベース構造を自動的に変更しません。あなたが記述したところから、$ statは実際には$ statであり、OneToOne関係でなければなりません。いずれにしても、D2マニュアルを読んで、どのように動作するかを確認する必要があります。 – Cerad