Classes:
class RefCountry < ActiveRecord::Base
has_many :cities, :class_name => :RefCity, :foreign_key => "country_id", :primary_key => "country_id"
end
class RefCity < ActiveRecord::Base
belongs_to :country, :class_name => :RefCountry, :primary_key => "country_id"
end
All links are working.
if I try to do
RefCity.joins(:country)
i get ActiveRecord::Relation
[
RefCity country_id: 1306, region_id: 4515, city_id: 67101, name_en: "Ust-Orda">,
RefCity country_id: 1285, region_id: 4483, city_id: 67102, name_en: "Ust-Tarka", ...]
But, I just want to get the data type
{city_id1, city_name1, country_id1, country_name1},
{city_id2, city_name2, country_id2, country_name2},
...
{city_idN, city_nameN, country_idN, country_name}
for use in the ajax
Try this out