在BeforeRemote相关方法中的Loopback where子句

时间:2016-03-23 09:37:48

标签: loopbackjs

Cart.beforeRemote('*.__destroyById__products', function(ctx, cart, next) {

});

如何在上面的远程钩子中添加where子句,例如后面的​​

ctx.args.filter.where = {"id_product_attribute": id_product_attribute};

id_product_attribute是相关型号产品中的一个字段。

此处,id_product_attribute是产品关系中的一个字段,映射到CartProduct模型。 上面的远程钩子在Cart模型中使用,我需要以某种方式将where子句应用于CartModel上下文中的CartProduct上下文。我还附上了cart.json和cart-product。 json供参考。

cart.json

{
"name": "Cart",
"plural": "carts",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true,
"mysql": {
"table": "pml_cart"
}
},
"mixins": {
"TimeStamp": {
"createdAt": "date_add",
"updatedAt": "date_upd",
"required": false
}
},
"hidden": [
"recyclable",
"date_add",
"date_upd"
],
"properties": {
"id_cart": {
"type": "number",
"id": true
},
"id_shop": {
"type": "number",
"required": true
},
"id_lang": {
"type": "number",
"required": true
},
"id_currency": {
"type": "number",
"required": true
},
"id_customer": {
"type": "number",
"required": true
},
"recyclable": {
"type": "number"
},
"date_add": {
"type": "date"
},
"date_upd": {
"type": "date"
}
},
"validations": [],
"relations": {
"products": {
"type": "hasMany",
"model": "CartProduct",
"foreignKey": "id_cart"
}
},
"acls": [
{
"accessType": "",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
}
],
"methods": {}
}

推车product.json

{
"name": "CartProduct",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true,
"mysql": {
"table": "pml_cart_product"
}
},
"mixins": {
"TimeStamp": {
"createdAt": "date_add",
"updatedAt": "date_add",
"required": false
}
},
"properties": {
"id_cart": {
"type": "number"
},
"id_product": {
"type": "number",
"id": true,
"required": true
},
"id_shop": {
"type": "number",
"required": true
},
"id_product_attribute": {
"type": "number",
"required": true
},
"quantity": {
"type": "number",
"required": true
},
"date_add": {
"type": "date"
}
},
"validations": [],
"relations": {
"image": {
"type": "hasOne",
"model": "ProductImage",
"foreignKey": "id_product"
},
"price": {
"type": "hasOne",
"model": "ProductShop",
"foreignKey": "id_product"
},
"lang": {
"type": "hasOne",
"model": "ProductLang",
"foreignKey": "id_product"
}
},
"acls": [],
"methods": {}
}

API请求如下

DELETE / api / carts /:id_cart / products /:id_product?id_product_attribute =:id_product_attribute

0 个答案:

没有答案