Sailsjs findOrCreate 使用什么属性来查找记录是否存在?

Sailsjs what attribute does findOrCreate use to find if a record exists?

我将 sailsjs 与 mysql 一起使用,并在下订单时使用它保存来自 shopify webhook 的数据。它 returns 一个 json 对象,其中一个属性是客户对象,我将其保存在与主订单 table 相关的不同 table 中。我在客户模型上使用 findOrCreate,所以我没有重复的客户。

waterline 可以使用特定属性来确定记录是否已经存在吗?客户对象(来自 shopify)有一个 id,但文档没有明确说明不同订单中的给定客户是否相同。此外,如果客户设置不同的付款方式、账单地址等,waterline 是否会为其创建新记录?

综上所述,我需要水线来使用customer_email 属性来判断记录是否存在。这可能吗?对不起,乱七八糟;我一边打字一边思考这个问题。

findOrCreate 接受 2 个参数和一个回调 您应该首先使用唯一标识键来确定记录是否存在。

例如

var findCriteria = { id: 1, customer_email: 'abc@example.com' };
var recordToCreate = { id: 1, customer_email: 'abc@example.com', name: 'ABC' };
Model.findOrCreate(findCriteria, recordToCreate, console.log);

findOrCreate

Checks for the existence of the record in the first parameter. If it can't be found, the record in the second parameter is created. If no parameters are passed, it will return the first record that exists. If no record is provided, it will either find a record with matching criteria or create the record if the object can not be found. Eg. Model.findOrCreate( findCriteria , recordToCreate , [callback] )