Open dousybox opened 5 years ago
@dousybox Hi! Thank you for the detailed map! This is amazing. Coming from Laravel backend, I didn't know most of this. I'm not sure if Vuex ORM should have full set, but sure this issue is going to be a dictionary to look up when considering a new relationship implementation.
I would like to focus on other issue that stopping Vuex ORM hitting v1.0.0, but I would like to keep this issue open until we make decision on these relationship.
@kiaking Thank you for your recognition, I'm very glad that it can be useful.
These table are the referrances that I used to find relational functions in my project.
When I sorted out the mapping table, I found that some relationships did not appear in the documents.
So I searched somthing about orm, then find out the Laravel framework.
And refer to it to fill out my mapping table, and added more relations about Through Relations
.
You're right, these relation mappings are not the primary issue.
They have not to be optimized yet, especially the Through Relations
. Some relationships seem to be duplicates, I'm still thinking.
This project are really awesome, I'm very happy to help it.
@dousybox Thanks! I think this mapping is pretty useful in general. Since these kind of things are tend to be different on every frameworks (even the names).
I could really use "Many To Many Through" for this exact reason: User.id -> pivot -> Role.id -> pivot -> Permissions.id
Currently you have to make a custom getter to make this work.
@FrittenKeeZ yea we should really support through
relations on all relation types.
As a side note, a getter is a more performant way of retrieving m:t:m relations.
Sure, if you can cache the result in some way. I don't know whether this is the most efficient way really...
/**
* Get unique permissions through roles.
*
* @return {Permission[]}
*/
get permissions () {
return [...new Set(this.roles.map(role => role.permissions).flat())].sort((a, b) => a.name.localeCompare(b.name))
}
/**
* Whether user has the given permission.
*
* @param {String} name
*
* @return {Boolean}
*/
hasPermission (name) {
let permissions = this.$store().getters['auth/permissions']
if (permissions === null) {
// Commit permissions to store for better performance.
permissions = this.permissions.map(permission => permission.name)
this.$store().commit('auth/permissions', permissions)
}
return permissions.includes(name)
}
I have collected some useful ORM relationships, and try to corresponding them to Vuex ORM methods.
But some of them have no corresponding methods.
Can anyone help me improve the table below?
normal
Through
Polymorphic