Thursday, October 29, 2009

Overriding a model's order when it has a different className

Hi.

I've got a model, Product, which has its $order variable set to
'Product.name ASC'. Usually this works fine, as you'd expect.

The tricky bit is that Product hABTM itself. When it does this, it
obviously needs to give the second instance of itself a different
className to avoid conflicts, so I specify the new className in the
order too:

var $hasAndBelongsToMany = array(
'Recommendation' => array(
'className' => 'Product',
'joinTable' => 'recommended_products',
'foreignKey' => 'viewed_product_id',
'associationForeignKey' => 'recommended_product_id',
'order' => 'Recommendation.name ASC',
'unique' => true
)
);

The bit I can't work out is why 'Recommendation.name ASC' appears to
be ignored. The query still tries to order by 'Product.name ASC', so
it doesn't work.

Although this happens to be a hABTM relationship, I've had the same
issues with others, such as a tree which belongsTo and hasMany itself.

I'm sure I'm missing something obvious, but can't figure out what. Is
there a simple way to override the model's default order when it has a
different className, so I don't need to manually specify it in the
find queries?

Thanks,
Zoe.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: