通过 2 个集合的关系定义基石
Relationship definition keystone via 2 collections
我的 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}
...
});
在注册我的用户模型之前,我想 link 他们回到管理员 UI。
对于银行账户 linking 我有:
// Linked Bank Accounts
User.relationship({
path: 'bankAccounts',
ref: 'BankAccount',
refPath: 'owner'
});
显示用户的银行账户。
但现在我想查看每个用户的交易。
有办法吗?
类似于:refPath: 'customerBankAccount.owner'
(不起作用)
或者keystone不支持这个?
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'
});
我的 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}
...
});
在注册我的用户模型之前,我想 link 他们回到管理员 UI。 对于银行账户 linking 我有:
// Linked Bank Accounts
User.relationship({
path: 'bankAccounts',
ref: 'BankAccount',
refPath: 'owner'
});
显示用户的银行账户。
但现在我想查看每个用户的交易。 有办法吗?
类似于:refPath: 'customerBankAccount.owner'
(不起作用)
或者keystone不支持这个?
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'
});