简体   繁体   中英

ManyToOne join in symfony2

For a game I have 2 entities: story and story_completed. Story is same for all users(here company), and story_completed indicates which user have seen/completed which story. Now I would like to show a list of stories for an user and show which are completed and which are not completed.

在此处输入图片说明

So, I created 2 entities:

...
table: story
id:
    id:
        type: integer
        generator: { strategy: AUTO }
fields:
    name:
        type: string

AND

...
table: story_completed
id:
    id:
        type: integer
        generator: { strategy: AUTO }
ManyToOne:
    story:
        targetEntity: Story
fields:
    company_id: 
        type: integer

But now, if I do a JOIN

SELECT s FROM Story s LEFT JOIN s.completed c WHERE ...

I get an error: Error: Class ...\\Story has no association named completed.

Maybe I misunderstood the manyToOne association, but how can I do this simple 2 tables connection and join in doctrine2? In fact I need only to know for a story if a user X have completed it or not. I don't need a collection or bidirectional connection.

You need to create a OneToMany relationship in story to story_completed and name it "completed". If you do you will be able to use the JOIN as you want it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM