【发布时间】:2018-01-16 01:25:09
【问题描述】:
使用 Rails 的 ActiveRecord 将两个子地址记录存储在以下 JSON sn-p 中的父发货记录下的最佳方法是什么?
显然,存储子记录的标准方法是配置普通的has_many-belongs_to 关系,但是在这种情况下,父记录“有两个”子记录,我可以' t 看到适当的情况,另外,has_many-belongs_to 关系不允许将一条记录定位到另一条记录是相同的方式(即:shipment.to_address 不起作用)
任何帮助将不胜感激。
谢谢
{
"id": "shp_vN9h7XLn",
"to_address": {
"id": "adr_zMlCRtmt",
"name": "Dr. Joe Bloggs",
"company": null,
"street1": "323 Some Dr",
"street2": null,
"city": "Example City",
"state": "XX",
"zip": "00000",
"country": "XX",
"phone": "0000000000",
"email": "example@example.com",
"created_at": "2013-04-22T05:39:56Z",
"updated_at": "2013-04-22T05:39:56Z"
},
"from_address": {
"id": "adr_VgoLT6Ex",
"name": "Some Rep",
"company": "Example Co.",
"street1": "43 Example St",
"street2": null,
"city": "Example City",
"state": "XX",
"zip": "00000",
"country": "XX",
"phone": "0000000000",
"email": "support@example.com",
"created_at": "2013-04-22T05:39:57Z",
"updated_at": "2013-04-22T05:39:57Z"
},
"tracking_code": null,
"refund_status": null,
"created_at": "2013-04-22T05:40:57Z",
"updated_at": "2013-04-22T05:40:57Z"
}
【问题讨论】:
标签: ruby-on-rails activerecord