Checking multiple existance checks results in empty WHEN clause
patrickbkr opened this issue · comments
Patrick Böker commented
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
Fernando Correa de Oliveira commented
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 :(
Fernando Correa de Oliveira commented
This seems to fix that. I'll merge it.
Patrick Böker commented
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