Query with Ruby on Rails

Scripts

New Member
Hi: I'm struggling with a rails query. Finally, I want to make a JSON response with the following contents: A listing of all countries which have at least one company, associated through "Address" and a count of how of how many companies reside in a country.Here is my simple model structure:\[code\]class Country < ActiveRecord::Base has_many :addressesendclass Address < ActiveRecord::Base belongs_to :country belongs_to :companyendclass Company < ActiveRecord::Base has_one :addressend\[/code\]What's the most elegant way to solve this with Rails?
 
Top