In SQL, this type of query needs what is known as an
EXCEPTION JOIN. Some RDBMSs actually implement this as a separate type (such as DB2), while others need to use a workaround. In your case, it amounts to (in SQL):
SELECT User.* FROM User LEFT JOIN UserHouse ON UserHouse.id_user = User.id WHERE UserHouse.id_user IS NULL
Which will yield the expected ‘not in a house’ records.
There are similar examples in a number of places on this site.
I’ve never used Doctrine, so I can’t help you there. But my best guess would be something like:
addWhere('uh IS NULL')
addWhere('uh.id_user IS NULL')
solved Relation to many and get without this