我无法找到解决此问题的最佳解决方案:
我有两张桌子,
TABLE order contains
pickup_address,
delivery_address
两个字段都是引用的外键
TABLE address contains,
id,
city
当然还有其他列,但它们与手头的查询无关。 基本上我所做的是:
SELECT * from order LEFT join address ON (pickup = id) LEFT join address ON (delivery = id )
类似的东西:)所以我有一行将2个地址组合成订单。我认为这不是一个干净的解决方案。
我尝试做的是让用户查询我的API以获取此订单,我不确定应该如何返回所有数据。
我是否在JSON中分隔订单和地址?像这样:
{
orders: [
{
id: "1",
pickUpAddress: "1",
deliveryAddress: "2",
}
addresses: [
{
id: "1",
....
},
{
id: "2",
}
]
}
基本上我做了当前的JSON响应,但每次我回复大约20多个订单。这有效吗?
{
code: 200,
data: {
orders: [
{
id: "1",
customer_id: "cust1",
reference: "asdfad",
state: "4",
pickUpAddress: "1",
pickUpDate: "2012-02-21",
deliveryAddress: "2",
deliveryDate: "2012-02-23",
pickup_street: "street 1",
pickup_housenumber: "1",
pickup_country: "belgium",
pickup_zipcode: "1000",
pickup_city: "brussels",
delivery_street: "street 2",
delivery_housenumber: "2",
delivery_country: "belgium",
delivery_zipcode: "1000",
delivery_city: "brussels"
}
]
}
}
答案 0 :(得分:0)
我会返回所有数据,除非有理由不这样做(例如大量数据)。 你为什么不呢?
但是,我会允许他们通过ID获取地址。给他们尽可能多的选择。