FCO / Red

A WiP ORM for Raku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Checking multiple existance checks results in empty WHEN clause

patrickbkr opened this issue · comments

use Test;
use Red;

model TestModel {
    has UInt     $.id          is serial;
    has Str $.started-at  is column{ :nullable };
    has DateTime $.finished-at is column{ :nullable };
}

my $*RED-DB = database 'SQLite';
#my $*RED-DB = database 'Pg', :host(Str), :user<patrick> :dbname<patrick>;
my $*RED-DEBUG = True;

schema(TestModel).drop;
TestModel.^create-table;

lives-ok {
    TestModel.^create: started-at => "hiea";
    for TestModel.^all.grep({ $_.started-at && !$_.finished-at }) -> $x { }
}, "Deflator and inflator don't die";

done-testing;

Produces the following SQL:

SELECT
   "test_model".id , "test_model".started_at as "started-at", "test_model".finished_at as "finished-at"
FROM
   "test_model"
WHERE
   1

It seems I've forgotten to test if it's the same column on both sides (https://github.com/FCO/Red/blob/master/lib/Red/AST/Optimizer/AND.pm6#L66) (and that should be false on that case. Would you like to test it? Im away from keyboard :(

This seems to fix that. I'll merge it.

I can confirm this works. I think the same fix needs to be applied in https://github.com/FCO/Red/blob/master/lib/Red/AST/Optimizer/OR.pm6#L112