Jak nadpisać: kolejność zdefiniowana w A ma wiele

Mam

class Authors 
has_many :books, :order => 'name ASC'

Próbuję odpytywać wszystkie książki posortowane według nazwy DESC

Authors.books.order('name DESC')

Ale wynik jest

SELECT * FROM .... ORDER BY name ASC, name DESC

A wyniki wracają z nazwą sortowaną ASC

Czy istnieje sposób na usunięcie pierwotnej kolejności w asocjacji lub nadpisanie jej? A może określenie zlecenia w relacji to zły pomysł?

Using Rails 3.0.3

Author: Christopher, 2010-11-17

3 answers

Użyj Zmień kolejność :

Authors.books.reorder('name DESC')
 87
Author: Ariejan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-16 13:46:47

.reorder() został wycofany w Rails 3.0.3 na rzecz .except(:order).order()

Więc użyj tego:

Authors.books.except(:order).order('name DESC')
 32
Author: Jon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-16 15:13:08
Author.first.books.reverse_order
 -1
Author: Subba Rao,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-20 03:34:08