我想知道是否可以使用find方法来根据类与另一个类的has_many关系对结果进行排序。例如Rails:使用has_many/belongs_to关系的顺序
# has the columns id, name
class Dog < ActiveRecord::Base
has_many :dog_tags
end
# has the columns id, color, dog_id
class DogTags < ActiveRecord::Base
belongs_to :dog
end
,我愿做这样的事情:
@result = DogTag.find(:all, :order => dog.name)
谢谢。
另请参阅如何设置关系本身的顺序:http://stackoverflow.com/questions/1530131/rails-order-using-a-has-many-belongs-to-relationship – Todd 2016-01-13 18:20:02