# Pastebin LV9qOiwq $ perl6 -Ilib -MRed -e ' model B is table { ... } model A is table { has UInt $.id is serial; has B @.bs is relationship{ .a-id } } model B { has UInt $.id is serial; has UInt $.a-id is referencing{ A.id }; has A $.a is relationship{ .a-id } } my $*RED-DB = database "SQLite"; A.^create-table; B.^create-table; my $a = A.^create; given $a { .bs.create; .bs.create; .bs.create } my $*RED-DEBUG = True; .say for $a.bs.map: { .id > 2 ?? "the big id is { .id }" !! "the small id is { .id }" } ' SQL : SELECT CASE WHEN id <= 2 THEN 'the small id is ' || id WHEN id > 2 THEN 'the big id is ' || id END as "data_1" FROM bbb WHERE bbb.a_id = ? BIND: [1] the small id is 1 the small id is 2 the big id is 3