LoginSignup
3
2

More than 5 years have passed since last update.

カスタムリポジトリが作成されない時の対処法

Posted at

EntityからCustomReopsitoryを作成しようとEntityにアノテーションを追加。

// src/Blogger/BlogBundle/Entity/Blog.php
/**
 * @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\BlogRepository")
 * @ORM\Table(name="blog")
 */
class Blog
{
    // ..
}

そして$ php app/console doctrine:generate:entities Blogger\BlogBundleを実行。
エラーはでないがカスタムRepositoryが作成されない。

ぐぐったところ、

推測ですが、バンドル内に複数の形式のマッピング情報ができてしまっていることが原因ではないかと思います。

・エンティティクラスに定義したアノテーション
・データベースからインポートした時のXML
http://docs.symfony.gr.jp/symfony2/cookbook/doctrine/reverse_engineering.html
の通りのコマンドであれば)

この状態で doctrine:generate:entities
を実行しても、アノテーションではなくXMLの方からメタデータを読み込んでしまうため、カスタム>リポジトリの記述が有効になりません。

ですので、もしバンドルの Resources/config/doctrine/
ディレクトリあたりに生成されたXMLファイルが残っているようでしたら、これを削除してから、再度
doctrine:generate:entities を実行してみてください。

ということで、EntityをDBから作成したときのxmlファイルを削除して再度コマンドを実行したらできました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2