0

create records in a subtable

Hello all

I'm trying to indset records in a subtable i have a table 'heste' holding name, age,birthday... and a training table with date,activity... i want to select alle horses in category 2 and lacation 1 (gives 6 horses)... the below script is not inserting a id for the parrent table, and it only inserts one record (should be 6)

any ideers ?

let p := (create 'Træning');
for d in (select Heste where Kategori = 2 and Lokation = 1) order by ID do
p.(Heste.id := d.id);
p.(Date := date(now()));

void
end;

4 replies

null
    • Fred
    • 3 yrs ago
    • Reported - view

    You are very close. You need to put the create code inside the for loop. Then you just need to add a variable that gathers the data for your current record.

     

    let curRec := this;

    for d in (select Heste where Kategori = 2 and Lokation = 1) order by ID do

    let p := (create 'Træning');

    p.(Heste := curRec);
    p.(Date := date(now()));

     

    It is actually very simple in Ninox to link records once you get the idea that you don't need to point at specific field names within the relationship. Just make sure you link the reference field names that you use in the tables that are linked.

    • Henrik_B
    • 3 yrs ago
    • Reported - view

    Thanks !!!

    • Fred
    • 3 yrs ago
    • Reported - view

    Oops, sorry. My bad. I did not take into account the For loop myself. :) You can skip the curRec variable.

    for d in (select Heste where Kategori = 2 and Lokation = 1) order by ID do

    let p := (create 'Træning');

    p.(Heste := d);
    p.(Date := date(now()));

    • Henrik_B
    • 3 yrs ago
    • Reported - view

    It works for me now!!