Sql 过滤多个模型

Sql 过滤多个模型,sql,ruby-on-rails,ruby,ruby-on-rails-3,Sql,Ruby On Rails,Ruby,Ruby On Rails 3,假设我有三个模型要作为json返回: Car: id, name, age, color, brand, created_at Bike: id, name, size, tire, created_at Bus: id, ps, consumption created_at 因此,我要做的是按照在创建的对这三个模型进行排序: (我想象的代码):[汽车、自行车、公共汽车].sort.order(“在描述时创建”) 因此,在最后,我有所有的三个模型在一个活动记

假设我有三个模型要作为json返回:

Car:  id, name, age, color, brand, created_at
Bike: id, name, size, tire,        created_at
Bus:  id, ps, consumption          created_at
因此,我要做的是按照在创建的
对这三个模型进行排序:

(我想象的代码):
[汽车、自行车、公共汽车].sort.order(“在描述时创建”)
因此,在最后,我有所有的三个模型在一个活动记录协会!这可能吗?谢谢,这是可能的

例如,如果模型对象
a
具有所有三种关联,则可以执行以下操作:

[a.cars, a.bikes, a.buses].flatten.sort_by{|obj| -obj.created_at}

回答得很好!但是你能给我推荐这样的东西吗?