You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm an objection user for 5 years. I just encountered this problem when doing a join on 5 tables. I want to fill one field "product" with one of the joined tables (product, buyback, appraisal). One of those tables will have a value and fill the "product" field. I managed to do it with raw query, but when I want to use objection I have this problem operator does not exist: outlet_transaksi_detail #>> unknown. Here is the code that I have created with objection and raw query.
The problem is when I use CASE WHEN.
use raw query
export function getAllReportOutletTransakasiRaw(data) {
return new Promise(async (resolve, reject) => {
try {
const { _outletUuid, _kasirUuid } = data;
const _knex = OutletTransaksiModel.knex();
const _results = await _knex.raw(
`
SELECT
ROW_NUMBER() OVER() AS nomor,
TO_CHAR(transaksi.created_at, 'HH12:MI:SS') AS waktu_dibuat,
transaksi.type,
transaksi.nomor_transaksi,
transaksi.id AS transaksi_id,
CASE
WHEN product.nama IS NOT NULL
THEN product.nama
WHEN buyback.nama IS NOT NULL
THEN buyback.nama
WHEN appraisal.jenis IS NOT NULL
THEN appraisal.jenis
ELSE '-'
END AS product,
transaksi.diskon,
details.quantity,
details.harga,
(details.quantity * details.harga) - transaksi.diskon AS total
FROM public.outlet_transaksi transaksi
LEFT JOIN outlet_transaksi_detail details
ON details.transaksi_id = transaksi.id
LEFT JOIN outlet_products product
ON product.id = details.product_id
LEFT JOIN outlet_buyback buyback
ON buyback.id = details.buyback_id
LEFT JOIN outlet_appraisal appraisal
ON appraisal.id = details.appraisal_id
WHERE transaksi.outlet_uuid = ?
AND transaksi.status = 'done'
AND transaksi.created_by = ?;
`,
[_outletUuid, _kasirUuid],
);
resolve(_results);
} catch (error) {
reject(error);
}
});
}
use objection
export function getAllReportOutletTransaksi(data) {
return new Promise(async (resolve, reject) => {
try {
const { _outletUuid, _kasirUuid, _start, _end } = data;
const _keyProduct = ref("details:product.nama").castText();
const _keyBuyback = ref("details:buyback.nama").castText();
const _keyAppraisal = ref("details:appraisal.jenis").castText();
const _results = await OutletTransaksiModel.query()
.select(
"outlet_transaksi.type",
"outlet_transaksi.nomor_transaksi",
// "details:product.nama AS product",
// "details:buyback.nama AS buyback",
// "details:appraisal.jenis AS appraisal",
"outlet_transaksi.diskon",
"details.quantity",
"details.harga",
"outlet_transaksi.created_by as kasir_uuid",
)
.select(
raw(
"TO_CHAR(outlet_transaksi.created_at, 'HH12:MI:SS') AS waktu_dibuat",
),
raw(
"(details.quantity * details.harga) - outlet_transaksi.diskon AS total",
),
raw("ROW_NUMBER() OVER() AS nomor"),
raw(
`
CASE
WHEN ?? IS NOT null
THEN ??
WHEN ?? IS NOT null
THEN ??
WHEN ?? IS NOT null
THEN ??
ELSE '-'
END AS product
`,
[
_keyProduct,
_keyProduct,
_keyBuyback,
_keyBuyback,
_keyAppraisal,
_keyAppraisal,
],
),
)
.leftJoinRelated("[details]")
.leftJoinRelated("[details.[product, buyback, appraisal]]")
.where("outlet_transaksi.outlet_uuid", _outletUuid)
.andWhere("outlet_transaksi.status", "done")
.andWhere(function () {
if (_kasirUuid) {
this.where("outlet_transaksi.created_by", _kasirUuid);
}
})
.modify("mod_range", _start, _end);
resolve(_results);
} catch (error) {
reject(error);
}
});
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm an objection user for 5 years. I just encountered this problem when doing a join on 5 tables. I want to fill one field "product" with one of the joined tables (product, buyback, appraisal). One of those tables will have a value and fill the "product" field. I managed to do it with raw query, but when I want to use objection I have this problem
operator does not exist: outlet_transaksi_detail #>> unknown
. Here is the code that I have created with objection and raw query.The problem is when I use
CASE WHEN
.use raw query
use objection
Thanks advance for the response...
Beta Was this translation helpful? Give feedback.
All reactions