简体   繁体   English

如何更改字段删除而不是回送中的id?

[英]How to change the field delete instead of id in loopback?

I want to the delete a few rows in MySQL table using loopabck. 我想使用loopabck删除MySQL表中的几行。 But I don't want to use the id to delete the record. 但我不想使用ID删除记录。 I'm trying it in Angular SDK. 我正在Angular SDK中尝试。 My code is: 我的代码是:

ModelName.destroyById({ fieldName : myValue })
                          .$promise
                          .then(function() {

                          });

I'd be very thankful for ideas. 我非常感谢您的想法。

Seems like you need to use the destroyAll method, which does what you want, but you need to set up remoting for it first, since it's disabled by default: 似乎您需要使用destroyAll方法,该方法可以实现您想要的功能,但是您需要首先为其设置远程处理,因为默认情况下它是禁用的:

  ModelName.remoteMethod('destroyAll', {
    isStatic: true,
    description: 'Delete all matching records',
    accessType: 'WRITE',
    accepts: {arg: 'where', type: 'object', description: 'filter.where object'},
    http: {verb: 'del', path: '/'}
  });

Then after that you regenerate your Angular client and you can use it like this in the client side: 然后,您可以重新生成Angular客户端,然后可以在客户端中像这样使用它:

ModelName.destroyAll({ filter: { fieldName : myValue }}).$promise.then(...)

Note that using destroyAll is risky as if you have any mistakes in your code you will end up losing data. 请注意,使用destroyAll很有风险,就好像您的代码中有任何错误一样,最终将导致数据丢失。 Enabling it to client side might be security concern. 在客户端启用它可能是出于安全考虑。

Another way to do this is to write your own remote method which uses destroyAll in turn with proper validation of the inputs. 完成此操作的另一种方法是编写自己的远程方法 ,该方法在正确验证输入的情况下依次使用destroyAll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM