Sorry for the long question, but i think its simple for experienced symfony and mongodb developer.
Q: If i generate repository class, all repository findAll(), findBy(), findOneBy(), findBy*() gets failed. Why it fails?
below my composer state.
"require":
{
"php": ">=5.3.9",
"symfony/symfony": "2.8.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.11.3",
"sensio/distribution-bundle": "~5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"doctrine/mongodb-odm": "^1.1",
"doctrine/mongodb-odm-bundle": "^3.2"
}
Controller method as below
/**
* @Route("survey/{token}", name="survey_index")
*/
public function indexAction($token){
// if i remove repository, below query gives perfect result.
$survey = $this->get('doctrine_mongodb')
->getRepository('CoreBundle:Survey')->findAll();
return $this->render('CoreBundle:Survey:index.html.twig',array('survey'=>$survey));
}
Document class as below
namespace CoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document(collection="survey_master")
* @ODM\Document(repositoryClass="CoreBundle\Repository\SurveyRepository")
*/
class Survey {
/**
* @ODM\Id
*/
protected $id;
/**
* @ODM\Field(type="string")
*/
protected $name;
// setters and getters below
}
If I remove
* @ODM\Document(repositoryClass="CoreBundle\Repository\SurveyRepository")
and perform cache clear, everything works perfect.
SurveyRepository class
namespace CoreBundle\Repository;
use Doctrine\ODM\MongoDB\DocumentRepository;
/**
* SurveyRepository
*
* This class was generated by the Doctrine ODM. Add your own custom
* repository methods below.
*/
class SurveyRepository extends DocumentRepository
{
}
Survey has two annotations with @ODM\Document which override themselves.
Put both parameters to a single annotation.