if have "bill" entity, might create bill instance via rest api assigning food ordered bill when go create new bill.
i.e. might make post request www.server.com/api/bills following parameters:
{ cost: 30.0, foods: [23, 1, 14] }
is better send array of ids or normal practice send array of objects? following:
{ cost: 30.0, foods: [ { id: 23, name: "chicken parmesan", price: 10.0 }, { id: 1, name: "scotch fillet steak", price: 10.0 }, { id: 14, name: "baramundi", price: 10.0 }, ] }
yes, sending ids fine, though want check assigned id legit.
if don't have ids yet , want create objects (or update!) through association – sending nested array objects way go.
also, forgot mention! if sending just ids – means sending "special" rails field – food_ids
, , rails magic. that's update of field, that's true rest.
i'd go food_ids
if have no need in changing or creating foods, , i'd go foods_attributes
(nested attributes) if i'd need to.
Comments
Post a Comment