M
M
mr jeery2019-02-22 21:15:15
PostgreSQL
mr jeery, 2019-02-22 21:15:15

How to use SQL query with to_tsquery and include?

I have two associated postgres sequelize models Lead and Unit.

Lead = {
        unitId: {
            type: DataTypes.INTEGER,

            references: {
                model: 'Unit',
                key: 'id',
                deferrable: sequelize.Deferrable.INITIALLY_IMMEDIATE,
            },
        },
        name: {
            type: DataTypes.STRING,
        }
}

Unit = {
        status: {
            type: DataTypes.STRING,
        },
        title: {
            type: DataTypes.STRING,
        },
}

There is a working search for Lead
SELECT * FROM "Lead" WHERE "postVector" @@ to_tsquery('english','query')

I want to supplement the SQL query with a search so that the Unit fields are added to the found Lead objects, based on the unitId.
This is simply done via include sequelize or .populate in mongo.
And here's how to do it based on a search in pure SQL? Help - hint, I'm a little hung up.
Output is needed something like this, where status and title are taken from the Unit model.
[
{name: examplename, status: examplestatus, title: exampletitle},
{name: examplename2, status: examplestatus2, title: exampletitle2},
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-02-22
@jeerjmin

What is include?
Banal join.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question