0

I need the following sql query converting to Propel:

SELECT tag.tag, count( content_tag.tag_id ) AS weight
FROM content_tag, tag
WHERE content_tag.tag_id = tag.id
GROUP BY content_tag.tag_id
ORDER BY weight DESC , tag.ord_id ASC

Any ideas on how to do the count clause?

Thank you

1 Answer 1

2
$c = new Criteria();
$c->addJoin(ContentTagPeer::TAG_ID,TagPeer::ID,Criteria::INNER_JOIN);
$c->add(ContentTagPeer::TAG_ID, 'Count(' . ContentTagPeer::TAG_ID . ') AS Weight' , Criteria::CUSTOM);
$c->addGroupByColumn(ContentTagPeer::TAG_ID);
$c->addAscendingOrderByColumn(TagPeer::ORD_ID);
$c->addDescendingOrderByColumn('Weight');

I think that could help solve it

1
  • I think you missed the Alias for the COUNT column. That Criteria won't work. In your third line, the second parameter should go like 'COUNT('.ContentTagPeer::TAG_ID.') AS WEIGHT'.
    – ncuesta
    Dec 22, 2010 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.