Generating select into join clause
See original GitHub issueI’m getting this SQL when i’m making a join clause:
select
"CALL_REQ"."ID",
"CALL_REQ"."DESCRIPTION",
"CUSTOMER"."CONTACT_UUID" "CUSTOMER_CONTACT_UUID",
"CUSTOMER"."FIRST_NAME" "CUSTOMER_FIRST_NAME",
"CUSTOMER"."LAST_NAME" "CUSTOMER_LAST_NAME"
from
"CALL_REQ"
inner join (select "CA_CONTACT".* from "CA_CONTACT") "CUSTOMER" on "CUSTOMER"."CONTACT_UUID" = "CALL_REQ"."CUSTOMER"
where "CALL_REQ"."PERSID" = ? and "CALL_REQ"."TYPE" = ?
My db connector is oracle. Here is my code:
// ticket.js
export default class Ticket extends Model {
static get tableName() {
return 'CALL_REQ';
}
static get idColumn() {
return 'PERSID';
}
static get relationMappings() {
const Contact = require('./contact').default;
return {
customer: {
relation: Model.BelongsToOneRelation,
modelClass: Contact,
join: {
from: `${Contact.tableName}.CONTACT_UUID`,
to: `${Ticket.tableName}.CUSTOMER`
}
}
}
}
}
// contact.js
export default class Contact extends Model {
static get tableName() {
return 'CA_CONTACT';
}
static get idColumn() {
return 'CONTACT_UUID';
}
}
And in my query js file i have
let fields = ['CALL_REQ.ID', 'CALL_REQ.DESCRIPTION']
.concat(['CUSTOMER.CONTACT_UUID as CUSTOMER_CONTACT_UUID',
'CUSTOMER.FIRST_NAME as CUSTOMER_FIRST_NAME',
'CUSTOMER.LAST_NAME as CUSTOMER_LAST_NAME']);
return await Ticket.query()
.findById(id)
.select(fields)
.joinRelated('customer', { alias: 'CUSTOMER' })
.andWhere(Ticket.tableName + '.TYPE', 'R');
What i’ve to do to get the next SQL?
sql
select
"CALL_REQ"."ID",
"CALL_REQ"."DESCRIPTION",
"CUSTOMER"."CONTACT_UUID" "CUSTOMER_CONTACT_UUID",
"CUSTOMER"."FIRST_NAME" "CUSTOMER_FIRST_NAME",
"CUSTOMER"."LAST_NAME" "CUSTOMER_LAST_NAME"
from
"CALL_REQ"
inner join "CA_CONTACT" "CUSTOMER" on "CUSTOMER"."CONTACT_UUID" = "CALL_REQ"."CUSTOMER"
where "CALL_REQ"."PERSID" = ? and "CALL_REQ"."TYPE" = ?
I’m using objection@2.0.8 Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
SQL SELECT INTO statement
This article covers the SQL SELECT INTO statement including syntax, parameters and use with multiple tables, filegroups and a WHERE ...
Read more >SQL SELECT INTO Statement - W3Schools
The SELECT INTO statement copies data from one table into a new table. SELECT INTO Syntax. Copy all columns into a new table:...
Read more >How to use SELECT... INTO with a JOIN? - Stack Overflow
Your PL/SQL is valid and acceptable provided: Table TABLE contains exactly 4 columns, corresponding to the 4 values you are selecting.
Read more >INTO Clause (Transact-SQL) - SQL Server | Microsoft Learn
The SELECT...INTO statement operates in two parts - the new table is created, and then rows are inserted. This means that if the...
Read more >SQL joins and how to use them - Launch School
This is done by adding additional JOIN clauses to your SELECT statement. To join multiple tables in this way, there must be a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @koskimas, I just got back from vacation and I haven’t tried it yet. I’d like to do it this weekend.
@moutb Any luck reproducing this?