tags:

views:

9

answers:

1
comment:
  tableName: comments
  columns:
    comment_id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    news_feed_id:
      type: integer(4)
  relations:
    newsFeed:
      class: newsFeed
      local: news_feed_id
      foreign: news_feed_id
      foreignAlias: comments

When I select newsFeeds and wanted to get comments for every newsFeed, Is it possible to get comments order by a particular column. I need to show the latest ones first. I hope my question is clear. I want to specify extra information in the relation to order by results of child table.

+1  A: 

As you wrote you want to 'order your results'. Schema is not a right place for that. You do it in a query.

You didn't paste your full schema I guess. I assumed that you have *created_at* field in comment class (if not, try using Timestampable behavior):

Doctrine_Query::create()
  ->select('n.*, c.*')
  ->from('newsFeed n')
  ->innerJoin('n.comment c')
  ->orderBy('c.created_at DESC');
kuba
It works, Thanks kuba. I have to modify it a little bit to make it work for me. Only changed innerJoin to leftJoin.
Salman Riaz