Javascript Objective.js如何在内部查询中使用外部值?

Javascript Objective.js如何在内部查询中使用外部值?,javascript,sql,postgresql,objection.js,Javascript,Sql,Postgresql,Objection.js,我正在处理一个更复杂的SQL查询,它必须在objective.js中。 以下是迄今为止的代码 const tagEntry = await Tag_overview.query() .where('playable') //the playable column is a boolean .whereExists( InnerTableName.query().findById([<normal variable>, tag.id]) //<=

我正在处理一个更复杂的SQL查询,它必须在objective.js中。 以下是迄今为止的代码

const tagEntry = await Tag_overview.query()
    .where('playable') //the playable column is a boolean
    .whereExists(
        InnerTableName.query().findById([<normal variable>, tag.id]) //<= tag.id is the id of the row in the outer query
            )
    )
    .orderBy(raw('random()'))// this randomly orders the selection
    .limit(1)
const tagEntry=wait Tag\u overview.query()
.where('playable')//可播放列是一个布尔值
.哪里有(

InnerTableName.query().findById([,tag.id])//首先确保您在model
InnerTableName

那么你应该能够做到:

.whereExists(
  InnerTableName.query().findById([theJsVariable, ref("Tag_overview.id")])
)
ref(…)是我所缺少的,所以事后看来,这是显而易见的,感谢更正的代码:)取消了2行注释,更改了这一位,删除了65行其他行,这是这个内部查询的解决方法。
.whereExists(
  InnerTableName.query().findById([theJsVariable, ref("Tag_overview.id")])
)