Feature: fetch related

pickledolives edited this page Jan 2, 2017 · 5 revisions

When a Web Interface expects a list of Objects in parameters

f.e.:

POST .../flight_bookings
request body:
{ price: 100, passengers: [{ name: "Me", age: 30 }, { name: "You", age: 20 }] }
  1. Create a Resource Class ("passengers") with an ID and attributes of said Object ("p_id", "name", "age"). Make it writeable and hit "Migrate".
  2. Use Web CLI to create some records for 1. ("passengers" -> create with { name: "Me", age: 30 } and { name: "You", age: 20 }) and store the IDs returned by server ("abc123", "def456").
  3. Create a parent Resource Class ("flights") with ID, an attribute named like Resource Class 1. ("passengers") and other attributes ("price")
  4. Create appropriate Web Interface with option “fetch related” enabled. This will take the provided IDs, fetch from database the according records and put them under :related Hash key in the params. As needed use “params formula” to modify the Hash with instance_eval like merge!(passengers: fetch(:related)[:passengers].map { |p| { name: p[:name], age: p[:age].to_i }).
  5. Create appropriate Target Mapping
  6. Use Web CLI to create some records for 3. ("flights" -> create with { price: 100, passengers: "abc123,def456" })
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.