简体   繁体   English

通过2个集合的关系定义重点

[英]Relationship definition keystone via 2 collections

I have the following models in my keystone.js project: 我的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}
    ...
});

Before registering my User model I want to link them back in the admin UI. 在注册我的用户模型之前,我想将它们链接回管理员界面。 For the Bankaccount linking I have: 对于银行账户链接,我有:

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

Which shows the bankaccounts of the User. 显示用户的银行帐户。

But now I want to view the transactions per User. 但是现在我想查看每个用户的交易。 Is there a way to do this? 有没有办法做到这一点?

Something like: refPath: 'customerBankAccount.owner' (which doesn't work) 类似于: refPath: 'customerBankAccount.owner' (无效)

Or is this not supported by keystone? 还是梯形校正不支持此功能?

This is currently not supported by Keystone, but you could add another reference to User in the Transaction schema to have them displayed in the Admin UI: Keystone当前不支持此功能,但是您可以在Transaction模式中添加对User另一个引用,以将其显示在管理界面中:

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

and: 和:

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

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

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