0
나는이 개 테이블이 : comment
에 comment
및 user
여러 엔티티로 Doctrine에서 다음 쿼리를 수행하는 방법은 무엇입니까?
나는 다음과 같은 열이 : id
, user_id
, conversation_id
, body
...
및 user
에 나는 다음과 같은 열이 있습니다 id
, username
을 ..
doctrine을 사용하여 다음 쿼리를 수행하고 싶습니다.
"SELECT c.*, u.username FROM comment c LEFT JOIN user u on c.user_id = u.id WHERE c.conversation_id = '5'"
다른 말로하면 테이블에있는 name
을 표시하고 싶은 의견 목록을 얻을 수 있습니다.
나는 SQL에서 그것을하는 방법을 알고 있지만 doctrine에서 그것을 할 수 없다.
그것은 다음과 비슷한 모습이 될 것입니다
$q = $this
->createQueryBuilder('u')
->where('u.conversationId = :conversationId')
->setParameter('conversationId', $conversationId)
->getQuery();
교리 코멘트 엔터티 :
Test\SocialBundle\Entity\Comment:
type: entity
table: comment
repositoryClass: Test\SocialBundle\Entity\CommentRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
conversationId:
type: integer
nullable: false
column: conversation_id
userId:
type: integer
nullable: false
column: user_id
body:
type: string
nullable: false
length: '300'
lifecycleCallbacks: { }
교리 사용자 엔터티 :
Test\UserBundle\Entity\User:
type: entity
table: user
repositoryClass: Test\UserBundle\Entity\UserRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
username:
type: string
length: '100'
nullable: true
column: username
name:
type: string
length: '100'
nullable: true
column: name
manyToMany:
roles:
targetEntity: Role
joinTable:
name: user_role
joinColumns:
user_id:
referencedColumnName: id
inverseJoinColumns:
role_id:
referencedColumnName: id
lifecycleCallbacks: { }
감사합니다!
것 같습니다. 당신은 외래 키들 대신에 객체쪽으로'ORM' 이동 논리를 사용하는 것을 안다. –