私はDoctrine 2をSlim 3のORMとして使用していますが、双方向関係を実装しようとするとオブジェクトマッピングセクションに詰まっていますプロパティの "@OneToMany"アノテーションはインポートされませんでした(Doctrine2)
/**
* Class Resource
* @package App
* @ORM\Entity
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="user_id", columns={"user_id"})}))
*/
class User
{
/**
* @ORM\ManyToOne(targetEntity="UserRoles", inversedBy="users")
* @ORM\JoinColumn(name="role_id", referencedColumnName="user_role_id")
*/
protected $user_role;
}
/**
* Class Resource
* @package App
* @ORM\Entity
* @ORM\Table(name="user_roles", uniqueConstraints={@ORM\UniqueConstraint(name="user_role_id", columns={"user_role_id"})}))
*/
class UserRoles
{
/**
* @ORM\OneToMany(targetEntity="User", mappedBy="user_role")
*/
protected $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
}
私は私がしようとすると例外を取得php vendor/bin/doctrine orm:schema-tool:update --force
出力は次のようになります。
[教義\共通\注釈\ AnnotationException] [意味論的エラー]注釈 "@OneToMany" I nプロパティApp \ Entity \ UserRoles :: $ usersはインポートされませんでした。この注釈に「使用」ステートメントを追加することを忘れていましたか?
私はセッターとゲッターとテキストの比率にコードの制約をStackOverflowのに起因するそれぞれのフィールドを削除した –
それは「@ORM \ OneToMany」です。詳細については、 'use'ステートメントを参照してください。 –
@AlexBlexは言った。また、 '' ManyToOne''と '' JoinColumn''に '' @ORM \ ''がありません –