2014-03-04 159 views
-2

我在我的项目中有两个模型,分别是供应商和地址模型。姓名按字母顺序

我在地址表中存储供应商地址信息,如first_name,last_name..etc。

class Supplier < ActiveRecord::Base 
    has_one :address, :as => :addressable 
end 

class Address < ActiveRecord::Base 
    belongs_to :addressable, :polymorphic => true 
end 

现在我想根据他的名字,按字母顺序排列所有供应商,任何人都可以知道吗?

+1

http://guides.rubyonrails.org/active_record_querying.html#ordering – sevenseacat

+0

谢谢您重播,但我们正在订购自己的模型。我希望供应商根据他的名字按字母顺序排列,这里地址表中的名称列不在供应商表格中。 – SIVA

+0

你将不得不更清楚你想做什么,最好是用代码。 – sevenseacat

回答

1
Supplier.includes(:address).order("addresses.name")