javascript - How to do ordering a select in Sequelize correctly? -


i can't simple version of http://docs.sequelizejs.com/en/latest/docs/querying/#ordering work. please help.


this query:

const result = await db.dbo__peach_payments_transactions .findone({   'order': [db.dbo__peach_payments_transactions, 'created_at', 'desc'],   'include': [{ model: db.dbo__orders, where: { 'users_id': userid} }] }); 

gives me error: typeerror: converting circular structure json


this query:

const result = await db.dbo__peach_payments_transactions.findone({   'order': 'dbo.peach_payments_transactions.created_at desc',   'include': [{ model: db.dbo__orders, where: { 'users_id': userid} }] }); 

gives me error: "invalid reference from-clause entry table "peach_payments_transactions""


and query looks should work:

const result = await db.dbo__peach_payments_transactions.findone({   'order': '"dbo.peach_payments_transactions"."created_at" desc',   'include': [{ model: db.dbo__orders, where: { 'users_id': userid} }] }); 

but gives me error: typeerror: cannot set property 'order' of undefined

it outputs sql though (see last line):

select    "dbo.peach_payments_transactions"."peach_payments_transactions_id", "dbo.peach_payments_transactions"."orders_id", "dbo.peach_payments_transactions"."payment_states_id",    "dbo.peach_payments_transactions"."response_data", "dbo.peach_payments_transactions"."token", "dbo.peach_payments_transactions"."result", "dbo.peach_payments_transactions"."reason_code",    "dbo.peach_payments_transactions"."reason_message", "dbo.peach_payments_transactions"."price", "dbo.peach_payments_transactions"."processed_at", "dbo.peach_payments_transactions"."created_at",   "dbo.peach_payments_transactions"."updated_at", "dbo.order"."orders_id" "dbo.order.orders_id", "dbo.order"."users_id" "dbo.order.users_id", "dbo.order"."email" "dbo.order.email",    "dbo.order"."phone" "dbo.order.phone", "dbo.order"."token" "dbo.order.token", "dbo.order"."shipped_at" "dbo.order.shipped_at", "dbo.order"."created_at" "dbo.order.created_at",    "dbo.order"."updated_at" "dbo.order.updated_at"     "dbo"."peach_payments_transactions" "dbo.peach_payments_transactions"    inner join "dbo"."orders" "dbo.order"    on      "dbo.peach_payments_transactions"."orders_id" = "dbo.order"."orders_id" ,     "dbo.order"."users_id" = '71e1989b-67d9-4712-ad71-51dfa56b32bd'    order "dbo.peach_payments_transactions".created_at desc limit 1; 

update - models

peach_payments_transactions:

    entity['peach_payments_transactions_id'] = {type: sequelize.uuid, primarykey: true, 'defaultvalue': sequelize.uuidv4};     entity['orders_id'] = helper.getforeignkey('orders_id', orders.getmodel(db));     entity['payment_states_id'] = helper.getforeignkey('payment_states_id', payment_states.getmodel(db));     entity['response_data'] = sequelize.text;     entity['token'] = sequelize.text;     entity['result'] = sequelize.text;     entity['reason_code'] = sequelize.text;     entity['reason_message'] = sequelize.text;     entity['price'] = sequelize.bigint;     entity['processed_at'] = sequelize.date;     const result = db.define('dbo.peach_payments_transactions', entity, options);     result.belongsto(orders.getmodel(db), {foreignkey: 'orders_id'});     result.belongsto(payment_states.getmodel(db), {foreignkey: 'payment_states_id'}); 

orders

    entity['orders_id'] = {type: sequelize.uuid, primarykey: true, 'defaultvalue': sequelize.uuidv4};     entity['users_id'] = helper.getforeignkey('users_id', users.getmodel(db));     entity['email'] = sequelize.text;     entity['phone'] = sequelize.text;     entity['token'] = sequelize.text;     entity['shipped_at'] = sequelize.date;     const result = db.define('dbo.orders', entity, options);     result.belongsto(users.getmodel(db), {foreignkey: 'users_id'}); 


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -