W
W
WebDev2014-12-22 11:54:03
MySQL
WebDev, 2014-12-22 11:54:03

How to use ORM in this case?

Hello, I ran into a problem in laravel 4, google does not help.
View request

DB::table('user')->leftJoin('payments', function($join) {
            $join->on('entity_type', '=', 'salary')
                 ->on('entity_id', '=', 'user.id')
        })->get()

Throws an error saying that the salary field was not found. And I need to compare with a line. In Google, the first thing they write is that in this case you need to pass this line to an anonymous function through use. Tried it, same error. What am I doing wrong? It is on joins that way, on where everything works. You have to write raw requests in such cases. Help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kulik, 2014-12-22
@kirill-93

Method description:
Then in order for the second parameter to be interpreted as a value, and not a field, you need to specify $where true

DB::table('user')->leftJoin('payments', function($join) {
            $join->on('entity_type', '=', 'salary', 'and', true)
                 ->on('entity_id', '=', 'user.id')
        })->get()

I
icetomcat, 2014-12-22
@kostia256

I don’t know about laravel, but you can write the condition `payments`.`entity_type` = 'salary' in WHERE, not necessarily ON. I myself faced such a problem the other day in another framework.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question