【问题标题】:Relationship definition keystone via 2 collections通过 2 个集合的关系定义基石
【发布时间】:2015-12-28 21:30:57
【问题描述】:

我的 keystone.js 项目中有以下模型:

/* Bankaccount.js */

var BankAccount = new keystone.List('BankAccount');
BankAccount.add({
    owner: {type: Types.Relationship, ref: 'User', initial: true, index: true},
    iban: { type: Types.Text, initial: true, index: true, required: true}
    ...
});


/* Transaction.js*/

var Transaction = new keystone.List('Transaction', {track:true});

Transaction.add({
    customerBankAccount: {type: Types.Relationship, ref: 'BankAccount', initial: true, index: true, required: true },
    merchantBankAccount: {type: Types.Relationship, ref: 'BankAccount', initial: true, index: true, required: true },
    ...
});


/* User.js */

var User = new keystone.List('User', {track:true});

User.add({
    name: { type: Types.Name, initial: true, index: true},
    email: { type: Types.Email, initial: true, index: true}
    ...
});

在注册我的用户模型之前,我想将它们链接回管理 UI。 对于银行帐户链接,我有:

// Linked Bank Accounts
User.relationship({
    path: 'bankAccounts',
    ref: 'BankAccount',
    refPath: 'owner'
});

显示用户的银行账户。

但现在我想查看每个用户的交易。 有没有办法做到这一点?

类似:refPath: 'customerBankAccount.owner'(不起作用)

或者keystone不支持这个?

【问题讨论】:

    标签: javascript node.js model keystonejs


    【解决方案1】:

    Keystone 目前不支持此功能,但您可以在 Transaction 架构中添加对 User 的另一个引用,以使其显示在管理 UI 中:

    Transaction.add({
        customer: {type: Types.Relationship, ref: 'User', initial: true, index: true},
        ...
    });
    

    和:

    // Linked Transactions
    User.relationship({
        path: 'transactions',
        ref: 'Transaction',
        refPath: 'customer'
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多