假设我有一个GRPC订单,它在生成时如下所示:
Google::Protobuf::DescriptorPool.generated_pool.build do
add_message "something.Order" do
optional :uuid, :string, 1
repeated :shipments, :message, 2, "something.Shipment"
...
end
end所以一个Order有很多shipments。当我在服务中创建要作为响应发回的订单时...如何创建多个货件?
我可以这样做吗:
order = Order.find(request.id)
Something::Order.new(uuid: order.id, shipments: [order.shipments)或者它需要是:
order = Order.find(request.id)
Something::Order.new(uuid: order.id, shipments: [order.shipments.attributes)我从these docs得到后者
发布于 2017-05-10 06:28:25
我不确定,但看起来这里使用了google-protobuf包?(https://github.com/google/protobuf)。
如果是这样的话,我不认为ruby-protobuf文档在这里是相关的。
要在这里使用Google::Protobuf,看起来您应该能够将一个Shipment对象数组添加到一个'Order‘实例的'shipments’字段。
https://stackoverflow.com/questions/43645201
复制相似问题