in Education by
If I have a "Bill" entity, I might create that bill instance via REST API by assigning the food ordered to the bill when I go to create a new bill. i.e. I might make a POST request to www.server.com/api/bills with following parameters: { cost: 30.0, foods: [23, 1, 14] } Is it better to send an array of ids or is it normal practice to send an array of objects? Like the 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 }, ] } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Yes, sending IDs is perfectly fine, though you want to check that assigned ID are legit. If you don't have an IDs yet and you want to create objects (or update!) through association – sending a nested array with objects is the way to go. Also, forgot to mention! If you are sending just ids – it means you are sending a "special" rails field – food_ids, and Rails do the magic. That's just an update of a field, that's true REST. I'd go with food_ids if I have no need in changing or creating foods, and I'd go with foods_attributes (nested attributes) if I'd need to.

Related questions

0 votes
    If I have a "Bill" entity, I might create that bill instance via REST API by assigning the food ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    having this code block of an example rails model class: class Block < ActiveRecord::Base has_many :bricks, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I store all of the Google Maps marker objects in a single array. Right now I am trying to set up ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    I try to merge some object into one array I did output by q = [["99","99","99"],["9" ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I am trying to sort an array of objects by the name field but the ordering is wrong. The order I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    What happens with the objects if the array is released?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    I have a field call query_data defined as text in my MySQL database. In my model I defined this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Which of these exceptions are related to the MyModel.objects.get(id=’123’)? 1. Http404 2. DatabaseError 3. MyModel.DoesNotExist 4. IntegrityError...
asked Jul 4, 2021 in Technology by JackTerrance
0 votes
    I have the following function [@bs.obj] external route: ( ~_method: string, ~path: string, ~action ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What is the problem Here ? I got an error shows ValueError: too many values to unpack This code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    What is the performance, disk usage and speed of a compound index(with an array index) and a compound ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Using the WCF web programming model one can specify an operation contract like so: [OperationContract] [WebGet ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    i have an array of objects in [ { "country": "USA", "payment": [ { "paymentType": "Visa" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
...