M
M
mShpakov2018-07-09 14:03:50
PostgreSQL
mShpakov, 2018-07-09 14:03:50

How to join on json column?

Needed:
Make a search for companies where users match certain search expressions. Users are connected with the company via the json property column where the object with the company_id property is stored.
I make a request like this:

DB::table('companies')
->join('users', 'users.properties.company_id', '=', 'companies.company_id')
->select(['companies.company_id', 'companies.properties', 'companies.created_at', 'companies.updated_at'])
->get();

But I get in response:
SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "properties"
LINE 1: ...pdated_at" from "companies" inner join "users" on "users"."p...
^ (SQL: select "companies"."company_id", "companies"."properties", "companies"."created_at", "companies"."updated_at" from "companies" inner join "users" on "users"."properties"."company_id" = "companies"."company_id")

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mShpakov, 2018-07-09
@mShpakov

I had to replace join with this
For some reason, Laravel does not normally accept castings inside a join

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question