現在、次のような「from」および「to」属性を持つTripというモデルがあります(質問のために簡略化されています):
class Trip < ActiveRecord::Base
attr_accessible :from_street, :from_zip, :from_country, :to_street, :to_zip, :to_country
...
end
これを次のようにリファクタリングしたいと思います。
class Trip < ActiveRecord::Base
has_one :from_location
has_one :to_location
...
end
class Location < ActiveRecord::Base
belongs_to :trip
attr_accessible :street, :zip, :country
...
end
私が達成しようとしているのは、「複雑な属性」として機能するモデルを作成することです。しかし、どのように、どこに関連付けを配置すればよいか、よくわかりません。上記は正しいですか?それとも、 Location ではなく Trip に所属する必要がありますか?