ListingモデルとCountryモデルがあります。各リストには国がありますが (住所の詳細の一部として)、各リストには複数の ExportCountries (リストの所有者が輸出する国) を含めることもできます。
A listing has_one country
A Country has_many listings
A listing has_and_belongs_to_many ExportCountries
An ExportCountry has_and_belongs_to_many Listings
2 つの別々のモデルがある場合、おそらく次のようにします。
class Listing < ActiveRecord::Base
belongs_to :country
has_and_belongs_to_many :export_countries
end
class Country < ActiveRecord::Base
has_many: listings
end
class ExportCountry < ActiveRecord::Base
has_and_belongs_to_many :listings
end
しかし、たった 1 つの Country モデルでそれを行うにはどうすればよいでしょうか。そうしないと、ExportCountry はまったく同じレコードを持ち、あまり DRY ではなく、Rails のようには見えないからです。