Better documentation/error handling regarding relationship paths
See original GitHub issueIt appears that the path
needs to be the plural of the model you are referencing.
In the docs we see the example of
User.relationship({ path: 'posts', ref: 'Post', refPath: 'author' });
But in this case changing path
to anything other than posts
causes problems. The docs say:
“path
- the path of the relationship reference on the Model”
which I don’t think quite makes this clear.
Further, if you do set it to something other than posts, no errors are ever thrown, but the admin ui stops working properly, and the browsers console logs errors like:
Uncaught TypeError: Cannot read property 'expandColumns' of undefined
but if you didn’t open your browsers console you’d never see any error messages, it just wouldn’t work properly.
Is it intended that that path
has to be the name of the model the relationship is with?
If yes, could the documentation be clearer here? Should we add some kind of check that throws a meaningful error for this?
If no, then this is a bug that needs fixing.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:25 (20 by maintainers)
Top GitHub Comments
@creynders if you are correct, and
path
should just be any name which the user decides, then there is a bug, since it has to be the name of the model.From the docs, my understanding was that
path
should be the user-readable name which will be displayed alongside the user, telling you which posts they have published (in the setting of your example). WhereasrefPath
would be displayed alongside the posts, and say which user authored the post.However, it appears that
path
MUST be the model in question. I.e. I think your example would break unless you changepath
fromarticles
toposts
.If your example should work, then this is a bug. If this is intended behaviour, then the docs are misleading. IMO this is a bug, and your example should work, but happy to be told otherwise.
Will do, though this article is pretty high on the search results for this topic, so I thought I’d save the next person some time.