1
doctrine2我發現一些職位,在這裏,但它仍然不能正常工作:LEFT JOIN與在右側的表,在一對多
我有2個實體故事StoryCompleted:
TA\Minigames\MinigameBundle\Entity\Story:
type: entity
table: story
id:
id:
type: integer
generator: { strategy: AUTO }
oneToMany:
completed:
targetEntity: StoryCompleted
mappedBy: story
fields:
cycle_nr:
type: integer
TA\Minigames\MinigameBundle\Entity\StoryCompleted:
type: entity
table: story_completed
id:
id:
type: integer
generator: { strategy: AUTO }
manyToOne:
story:
targetEntity: Story
fields:
company_id:
type: integer
completed:
type: boolean
我想得到所有故事的列表,並知道哪些故事是由COMPANY_ID = 1可以看出,所以我嘗試了左連接:
SELECT s FROM MGMinigameBundle:Story s LEFT JOIN s.completed c WHERE s.cycle_nr = 1 AND (c.company_id = $company_id OR c is NULL)
我沃爾德希望得到一個$ COMPANY_ID是這樣的:
story_id completed
1 1
2 -
3 -
但是,在每個Story中,我得到了所有完成的實體(對於所有$ company_id),而不是一個,對於給定的$ company_id,必須遍歷它們以找到我需要的實體。 :(