Mongodb rails 按belongs_to 关系排序

问题描述

在我的班级中,我有一个所属关系

Class MyClass

  belongs_to :reason,:class_name => 'Reason',autosave: false

然后上原因类

class Reason
  has_many :my_class,class_name: 'MyClass',validate: false
  field name

所以现在我想通过原因的名称字段对 MyClass 集合的列表进行排序。

MyClass.collection.aggregate() //sort by reason name

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)