I have an Entity "BlogPosts" with yml mapping:
type: entity
table: blog_posts
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
body:
type: text
created_at:
type: datetime
manyToMany:
replies:
targetEntity: BlogPosts
inversedBy: replyTo
orderBy: {"id": "DESC"}
orphanRemoval: true
joinTable:
name: blog_post_replies
joinColumns:
reply_to_id:
referencedColumnName: id
inverseJoinColumns:
reply_id:
referencedColumnName: id
replyTo:
targetEntity: BlogPosts
mappedBy: replies
manyToOne:
user:
targetEntity: User
inversedBy: posts
joinColumns:
user_id:
referencedColumnName: id
nullable: false
The problem is, when i try to fetch the data using a JOIN, the result is empty.
$query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p JOIN p.replies rl WHERE p.user = 1");
$posts = $query->getResult(); // Returns empty array
But it works perfectly without a join:
$query = $em->createQuery("SELECT p FROM <Bundle>:BlogPosts p WHERE p.user = 1");
$posts = $query->getResult(); // Works as intended
What am i missing? I am really desperate :(
EDIT: Just found out, that it returns only posts, that have replies. How can i select all posts and if it has replies, replies too?