我有 3 个模型:
class Depot < ActiveRecord::Base
has_many :car_amounts
has_many :cars, :through => :car_amounts
end
class CarAmount < ActiveRecord::Base
belongs_to :depot
belongs_to :car
end
class Car < ActiveRecord::Base
has_many :car_amounts
has_many :depots, :through => :car_amounts
end
存储包含仓库、数量和汽车数据的 json 参数的最佳方式是什么。像这样的东西:
{
"Depots": {
"title": "Dealer1"
},
"Amounts": [
{
"amount": "1"
"car": [
{
"Type": "supercar1"
}
]
},
{
"amount": "5"
"car": [
{
"Type": "supercar2"
}
]
},
]
}