私はクラスUserを持っており、クラスArticleとの関係:
/**
* @ORM\OneToMany(targetEntity="Article", mappedBy="author", cascade={"persist"})
* @var ArrayCollection $articles
*/
protected $articles;
クラスArticleで私は逆の関係を持っています:
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="articles")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
protected $author;
私は以下を使用して記事を取得します:
$article = $this->getDoctrine()
->getRepository("IftodiDesignBundle:Article")
->findOneBy(array(
'title' => $title,
));
ユーザーを取得しようとすると:
$article->getAuthor();
var_dump return:
object(Proxies\IftodiDesignBundleEntityUserProxy)[305]
private '_entityPersister' =>
object(Doctrine\ORM\Persisters\BasicEntityPersister)[309]
protected '_class' =>
object(Doctrine\ORM\Mapping\ClassMetadata)[113]
public 'reflFields' =>
array (size=8)
...
private '_prototype' => null
public 'name' => string 'Iftodi\DesignBundle\Entity\User' (length=31)
public 'namespace' => string 'Iftodi\DesignBundle\Entity' (length=26)
public 'rootEntityName' => string 'Iftodi\DesignBundle\Entity\User' (length=31)
public 'customRepositoryClassName' => null
public 'isMappedSuperclass' => boolean false
public 'parentClasses' =>
array (size=0)
...
public 'subClasses' =>
array (size=0)
...
public 'namedQueries' =>
array (size=0)
...
public 'identifier' =>
array (size=1)
...
public 'inheritanceType' => int 1
public 'generatorType' => int 4
public 'fieldMappings' =>
array (size=7)
...
public 'fieldNames' =>
array (size=7)
...
public 'columnNames' =>
array (size=7)
...
public 'discriminatorValue' => null
public 'discriminatorMap' =>
array (size=0)
...
public 'discriminatorColumn' => null
public 'table' =>
array (size=1)
...
public 'lifecycleCallbacks' =>
array (size=0)
...
public 'associationMappings' =>
array (size=1)
...
public 'isIdentifierComposite' => boolean false
public 'containsForeignIdentifier' => boolean false
public 'idGenerator' =>
object(Doctrine\ORM\Id\IdentityGenerator)[101]
...
public 'sequenceGeneratorDefinition' => null
public 'tableGeneratorDefinition' => null
public 'changeTrackingPolicy' => int 1
public 'isVersioned' => null
public 'versionField' => null
public 'reflClass' =>
object(ReflectionClass)[112]
...
public 'isReadOnly' => boolean false
protected '_conn' =>
object(Doctrine\DBAL\Connection)[120]
protected '_conn' =>
object(Doctrine\DBAL\Driver\PDOConnection)[356]
...
protected '_config' =>
object(Doctrine\DBAL\Configuration)[127]
...
protected '_eventManager' =>
object(Doctrine\Common\EventManager)[124]
...
protected '_expr' =>
object(Doctrine\DBAL\Query\Expression\ExpressionBuilder)[119]
...
private '_isConnected' => boolean true
private '_transactionNestingLevel' => int 0
private '_transactionIsolationLevel' => int 2
private '_nestTransactionsWithSavepoints' => null
private '_params' =>
array (size=7)
...
protected '_platform' =>
object(Doctrine\DBAL\Platforms\MySqlPlatform)[118]
...
protected '_schemaManager' => null
protected '_driver' =>
object(Doctrine\DBAL\Driver\PDOMySql\Driver)[121]
...
private '_isRollbackOnly' => boolean false
protected '_platform' =>
object(Doctrine\DBAL\Platforms\MySqlPlatform)[118]
protected 'doctrineTypeMapping' => null
protected 'doctrineTypeComments' => null
protected '_em' =>
object(Doctrine\ORM\EntityManager)[117]
private 'config' =>
object(Doctrine\ORM\Configuration)[128]
...
private 'conn' =>
object(Doctrine\DBAL\Connection)[120]
...
private 'metadataFactory' =>
object(Doctrine\ORM\Mapping\ClassMetadataFactory)[116]
...
private 'repositories' =>
array (size=3)
...
private 'unitOfWork' =>
object(Doctrine\ORM\UnitOfWork)[115]
...
private 'eventManager' =>
object(Doctrine\Common\EventManager)[124]
...
private 'hydrators' =>
array (size=0)
...
private 'proxyFactory' =>
object(Doctrine\ORM\Proxy\ProxyFactory)[114]
...
private 'expressionBuilder' => null
private 'closed' => boolean false
protected '_queuedInserts' =>
array (size=0)
empty
protected '_rsm' => null
protected '_columnTypes' =>
array (size=0)
empty
private '_insertSql' => null
protected '_selectColumnListSql' => null
protected '_selectJoinSql' => null
protected '_sqlAliasCounter' => int 0
protected '_sqlTableAliases' =>
array (size=0)
empty
private '_identifier' =>
array (size=1)
'id' => string '1' (length=1)
public '__isInitialized__' => boolean false
protected 'id' => null
protected 'username' => null
protected 'name' => null
protected 'email' => null
protected 'password' => null
protected 'salt' => null
protected 'role' => null
protected 'articles' => null
ArticleEntityを使用して正しいリレーションシップとgetUserを作成するのを手伝ってください。
私はDoctrineでSymfony2を使用しています。
編集:
記事エンティティは次のとおりです:http: //pastebin.com/ZBQPehGL ユーザーエンティティは次のとおりです:http://pastebin.com/McEYdZ9W
プロファイラーはこのクエリを表示しません:
$articles = $this->getDoctrine()
->getRepository("IftodiDesignBundle:Article")
->findAll();