This is a slightly different use than I've seen others post about.
I have a collection of members. For a some users, I would like the "name" to display just the first name with last-initial.
This is would be useful because organization leaders can see the full member roster. A parent can see the roster, but cannot see the full name of other members.
Even if I pre-calculate and store it in the database, the current access level is what would determine the field to use. So the error about being unable to use a non-relationship virtual field for useAsTitle would persist.
Is there any sort of workaround, even a convoluted one?
const virtualNameHook: FieldHook<Member, string, Member> =
({ siblingData, req }) => {
//TODO: Some access method finding particular role
return req.user
? `${siblingData.firstName} ${siblingData.lastName}`
: `${siblingData.firstName} ${siblingData.lastName?.slice(0,1)}`;
};
//....
{
name: 'name',
virtual: true,
type: 'text',
hooks: {
afterRead: [
virtualNameHook
]
}
},