Loopbackjs 如何查询属性在环回中包含值的对象

Loopbackjs 如何查询属性在环回中包含值的对象,loopbackjs,strongloop,Loopbackjs,Strongloop,我有一个模型事件,它引用了许多用户 "relations": { "attendees": { "type": "referencesMany", "model": "user", "foreignKey": "attendeeIds", "options": { "validate": true, "forceId": false, "persistent": true } } 如何查询Attenders属性包含给

我有一个模型
事件
,它引用了许多
用户

"relations": {
  "attendees": {
    "type": "referencesMany",
    "model": "user",
    "foreignKey": "attendeeIds",
    "options": {
      "validate": true,
      "forceId": false,
      "persistent": true
   }
}
如何查询
Attenders
属性包含给定值的事件<代码>与会者是一个包含用户ID的数组

例如:

Event.find({
    where: {
      attendees: {
        contains: givenUserId
      }
    }
  }
)

此功能被称为“2级属性上的过滤器”,如前所述,目前正在为内存和MongoDB连接器实施此功能。它仍然有一些问题。 对于SQL连接器,这还不受支持,正如本开放式讨论链接中所述,它需要一些时间,这是目前无法提供的

可能使用regexp解决问题,该方法将应用于底层JSON字符串,并通过直接执行SQL

简单的实现可以是:

AnyModel.getApp((err, app) => {
  if (err) {
    console.log(err);
    next(err);
  }

  // Using MySQL
  const MySQL = app.dataSources.MySQL;

  MySQL.connector.execute(`select * from Table where column like '%${string}%'`,
    [], {}, (err, data) => {
      if (err) {
        console.log(err);
        next(err);
      }

      console.log(data);
      next();
    });
});

此功能被称为“2级属性上的过滤器”,如前所述,目前正在为内存和MongoDB连接器实施此功能。它仍然有一些问题。 对于SQL连接器,这还不受支持,正如本开放式讨论链接中所述,它需要一些时间,这是目前无法提供的

可能使用regexp解决问题,该方法将应用于底层JSON字符串,并通过直接执行SQL

简单的实现可以是:

AnyModel.getApp((err, app) => {
  if (err) {
    console.log(err);
    next(err);
  }

  // Using MySQL
  const MySQL = app.dataSources.MySQL;

  MySQL.connector.execute(`select * from Table where column like '%${string}%'`,
    [], {}, (err, data) => {
      if (err) {
        console.log(err);
        next(err);
      }

      console.log(data);
      next();
    });
});