B
B
bondle2020-07-29 14:38:04
Doctrine ORM
bondle, 2020-07-29 14:38:04

What would a query with QueryBuilder look like?

I have a sql query

SELECT game.* FROM game f 
            JOIN ( SELECT RAND() * (SELECT MAX(id) FROM game) AS max_id ) AS m 
            JOIN game_buffer on game_buffer.game_id = f.id 
        WHERE f.id >= m.max_id and f.`start_time` between :from 
          and  :to and game_buffer.source_id = :source ORDER BY f.id LIMIT 1

I would like to use QueryBuilder to form it, but I have no idea how to make a join
JOIN ( SELECT RAND() * (SELECT MAX(id) FROM game) AS max_id ) AS m

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2020-07-29
@bondle

Not directly, because DQL doesn't have a RAND() . If you want, you can add your .
Also, although subqueries can be done through QueryBuilder, the resulting construction will look very strange. In addition, it is important to remember that QueryBuilder is a query building tool, for example, if you need to add some parts of the query depending on the application logic. If the query itself is static, then it is quite possible to use DQL directly. QueryBuilder is compiled into it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question