A
A
Anton2015-05-28 15:08:40
Laravel
Anton, 2015-05-28 15:08:40

How to make complex on in join using Query Builder in Eloquent?

There is a query that works 100%, I'm interested in how to transfer this part of it to Query Builder

left join tbl2 
    on tbl1.parent_id= tbl2.parent_id 
    and (
        isnull(tbl2.id) 
        or (
            tbl2.time = '1970-01-01 00:00:00' 
            and tbl2.cmd in (0, 1) 
        )
    )

construction like this does not work:
->leftJoin($rawTrades, function($leftJoin) {
    $leftJoin
        ->on("tbl1.parent_id", '=', 'tbl2.parent_id')
        ->on(function($query){
            $query->whereNull('tbl2.id')
                ->orWhere(function($query){
                    $query
                        ->where('tbl2.time', '=', '1970-01-01 00:00:00')
                        ->whereIn("tbl2.cmd",  [0,1]);
                 });
        });
})

UPD: the question is removed - it turned out to remove one condition, and you can do without closure in on, if someone suddenly needs it - this is currently impossible.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question