adminjs
adminjs copied to clipboard
Extend reference with reference key
Right now many to one relationship is handled that way: property which is a foreignKey gets type "reference" and system tries to use this propety to find relation by primeryKey. So let say we have User collection and Post collection.
Post has Property (BaseProperty) userId which is a reference set to "User". So when system populates records it knows that after fetching Posts he hast to populate userId with User model.
But this logic doesn't handle a keys when we have a reference to a different key than a primary. So lets suppose that in our example Posts have property accountId and it is reference to User but not to User.id but to User.accountId. In current implementation handling this is not possible.
In this task we will have to make it happen
How to do this? We simply have to return from BaseProperty#reference not a stiring but an object: { model: // old reference externaKey?: // when not set - it is primary key }
Also, we will have to allow people to change that in PropertyOptions and change a way how Populator and Filter work.
Blocker: #251
unfortunately this is bigger task. We moved populator logic to the core. Now it has 2 methods for searching: findOne and findMany - both finds by primary key. In order to implement this feature we will have to allow all adapters to find by many for any particular field (not just the primary key)
I assume the only current way to get this to work currently is with a custom component that does the querying manually?
Is there any short-term plans for this to be implemented?
+1
@wojtek-krysiak any updates ?
+1
+1