views:

37

answers:

0

How can I get DISTINCT translated results.

My scenario is the following:

  • I have a model named Project.
  • One of the fields is called location.
  • Many projects share the same location.

The Question is: How can I retrieve translated DISTINCT locations. It seems like normal find with DISTINCT location does not join i18n table thus returning non translated results.

I would normalize the database and have locations in a different table but someone else has already built that and there is no time fto rebuild. In addition cakephp does not translate associated models.

One idea would be to use bindTranslation however I am not sure how to use the DISTINCT value with bindTranslation. I have tried without success.

This is the code I'm using at the moment but I cannot get DISTINCT results.

$this->Project->bindTranslation(array('location' => 'nameTranslation'));
$locations = $this->Project->find('all', array('fields' => 'DISTINCT location', 'order' => 'location ASC'));

Any help would be much appreciated.