0

I have the following models in my keystone.js project:

/* 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)

Or is this not supported by keystone?

JasperV
  • 656
  • 1
  • 9
  • 19

1 Answers1

0

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:

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

and:

// Linked Transactions
User.relationship({
    path: 'transactions',
    ref: 'Transaction',
    refPath: 'customer'
});
Rudi
  • 2,987
  • 1
  • 12
  • 18