Post:
columns:
content: string(1000)
max_comments: integer
relation:
Comments:
class: Comment
local: id
foreign: post_id
Comment:
columns:
post_id: integer
content: string(100)
<?php
//...snip
$q = Doctrine_Query::create()->from('Post p, p.Comments c')->select('p.*, c.*, COUNT(c.id) AS comment_count')->having('comment_count <= p.max_comments');
$q->getSql(); //produces '... HAVING a2__0 <= p.max_comments ...'
//instead of '... HAVING a2__0 <= a__max_comments ...'