[英]How i can make a for in a model return query in adonis / node.js?
I have this query that's me return an array of questions:我有这个查询,我返回一系列问题:
const questions = await Question
.query()
.all()
console.log(questions)
But when i make a console.log in questions, i get very informations and i cant' find the array of objects relations.但是当我提出一个console.log 问题时,我得到了很多信息,我找不到对象关系数组。 This is why show my console.log()
这就是为什么显示我的console.log()
QueryBuilder {
Model:
{ [Function: BookUnitQuestion]
'$booted': true,
'$hooks': { before: [Hooks], after: [Hooks] },
'$queryListeners': [],
'$globalScopes': GlobalScopes { scopes: [] },
QueryBuilder: null },
connectionString: '',
db:
Database {
connectionClient: 'pg',
knex:
{ [Function: knex]
Promise: [Function],
queryBuilder: [Function: queryBuilder],
raw: [Function: raw],
batchInsert: [Function: batchInsert],
transaction: [Function: transaction],
initialize: [Function: initialize],
destroy: [Function: destroy],
ref: [Function: ref],
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
off: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
with: [Function],
select: [Function],
as: [Function],
columns: [Function],
column: [Function],
from: [Function],
fromJS: [Function],
into: [Function],
withSchema: [Function],
table: [Function],
distinct: [Function],
join: [Function],
joinRaw: [Function],
innerJoin: [Function],
leftJoin: [Function],
leftOuterJoin: [Function],
rightJoin: [Function],
rightOuterJoin: [Function],
outerJoin: [Function],
fullOuterJoin: [Function],
crossJoin: [Function],
where: [Function],
andWhere: [Function],
orWhere: [Function],
whereNot: [Function],
orWhereNot: [Function],
whereRaw: [Function],
whereWrapped: [Function],
havingWrapped: [Function],
orWhereRaw: [Function],
whereExists: [Function],
orWhereExists: [Function],
whereNotExists: [Function],
orWhereNotExists: [Function],
whereIn: [Function],
orWhereIn: [Function],
whereNotIn: [Function],
orWhereNotIn: [Function],
whereNull: [Function],
orWhereNull: [Function],
whereNotNull: [Function],
orWhereNotNull: [Function],
whereBetween: [Function],
whereNotBetween: [Function],
andWhereBetween: [Function],
andWhereNotBetween: [Function],
orWhereBetween: [Function],
orWhereNotBetween: [Function],
groupBy: [Function],
groupByRaw: [Function],
orderBy: [Function],
orderByRaw: [Function],
union: [Function],
unionAll: [Function],
having: [Function],
havingRaw: [Function],
orHaving: [Function],
orHavingRaw: [Function],
offset: [Function],
limit: [Function],
count: [Function],
countDistinct: [Function],
min: [Function],
max: [Function],
sum: [Function],
sumDistinct: [Function],
avg: [Function],
avgDistinct: [Function],
increment: [Function],
decrement: [Function],
first: [Function],
debug: [Function],
pluck: [Function],
clearSelect: [Function],
clearWhere: [Function],
clearOrder: [Function],
insert: [Function],
update: [Function],
returning: [Function],
del: [Function],
delete: [Function],
truncate: [Function],
transacting: [Function],
connection: [Function],
client: [Client_PG] },
_globalTrx: null },
query:
Builder {
client:
Client_PG {
config: [Object],
logger: [Logger],
connectionSettings: [Object],
driver: [PG],
pool: [Pool],
valueForUndefined: [Raw],
_events: [Object],
_eventsCount: 4,
makeKnex: [Function: makeKnex],
version: '12.0,' },
and: [Circular],
_single: { table: 'book_unit_question', only: false },
_statements: [ [Object] ],
_method: 'select',
_debug: false,
_joinFlag: 'inner',
_boolFlag: 'and',
_notFlag: false,
subQuery: [Function],
_events: [Object: null prototype] { query: [Function] },
_eventsCount: 1 },
_eagerLoads: { book_unit: [Function] },
_sideLoaded: [],
_visibleFields: undefined,
_hiddenFields: undefined,
_withCountCounter: -1,
scopesIterator: ScopeIterator { _scopes: [], _ignoreList: [] } }
This is showing in my browser, i need to manipulate this data.这显示在我的浏览器中,我需要操作这些数据。
How i can make a apply a for in question?我如何申请有问题的申请?
i need something like for(let i=0;i我需要类似 for(let i=0;i
0: {id: 5, book_unit_id: 5, question_form: "Texto", option_form: "Texto", type_answer: "Aberta",…}
1: {id: 7, book_unit_id: 5, question_form: "Texto", option_form: "Texto", type_answer: "Aberta",…}
2: {id: 8, book_unit_id: 6, question_form: "Texto", option_form: "Texto", type_answer: "Aberta",…}
when you display in console
that time you convert in json using toJSON()
like this当您在console
中显示时,您使用toJSON()
像这样在 json 中转换
const questionsjson= questions.toJSON()
console.log(questionsjson)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.