i use doctrine 1.2 and here is my schema:

```
ProviderProduct:
 columns:
   provider_id: 
     type: integer
     primary: true
   product_id:
     type: integer
     primary: true
   num:
     type: integer
     default: 0
     unsigned: true
Provider: 
 columns:
   name: {type: string(255), notnull: true, notblank: true, unique: true}
 relations:
   Products:
     class: Product
     local: provider_id
     foreign: product_id
     refClass: ProviderProduct
Product:
 columns:
    #a lot of columns
 relations:
   Providers:
     class: Provider
     local: product_id
     foreign: provider_id
     refClass: ProviderProduct

```

What i want is get product with max num (this is ammount) for specific provider.
I tried this query:

```
$query = Doctrine_Query::create()->select('p.*')
                                     ->from('Product p')
                                     ->innerJoin('p.Providers pr')
                                     ->where('pr.name = ?', 'WhiteStore')
                                     ->orderBy('ProviderProduct.num');
$query->fetchOne();

```

The result sql query:

```
SELECT p.* FROM product p 
INNER JOIN provider_product p3 ON (p.id = p3.product_id) 
INNER JOIN provider p2 ON p2.id = p3.provider_id, provider_product p4 
WHERE (p2.name = ?) ORDER BY p4.num

```

As you can see it doesnt order by num field. So, what is the right dql for my task ?