嗨:我正在用rails查询工作。最后,我想对以下内容做出JSON响应:所有国家的列表,包括至少一个公司,通过“地址”关联并计算一个国家有多少家公司。 这里是我的简单的模型结构:用Ruby on Rails进行查询
class Country < ActiveRecord::Base
has_many :addresses
end
class Address < ActiveRecord::Base
belongs_to :country
belongs_to :company
end
class Company < ActiveRecord::Base
has_one :address
end
什么是使用Rails来解决这个最优雅的方式?
你已经试过了什么?到目前为止显示你的代码尝试,你会得到更好的回应。 – Timothy 2010-02-26 10:48:47