0

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.

enter image description here

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.

Ilona
  • 357
  • 3
  • 10
degressor
  • 358
  • 4
  • 16
  • I am not sure how accurate your diagram is but there is a typo with the table name. "sotry_completed". Another problem is that because the relation is only in the direction Story_completed->Story you cannot run a query in the directory Story->Story_completed. Looking at your entities I think it might more sense anyway to make the relation bidirectional. – Daniel Cannon Jan 02 '13 at 10:35

1 Answers1

0

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

hosseio
  • 1,142
  • 2
  • 12
  • 25