-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to get multi-level relations #252
Comments
There is no shortcut to flatten things, but you can do:
|
Ya i see that, but then I'm left to do work in process that the dB should be able to do easily. But, not quite what I meant. I suppose I'm looking for a way to access things that are more than one table / join a way.
It seems like a reasonable thing for an orm/odm to be able to do. Am I explaining this well enough? |
Not really, what's the work left in process? |
If you are trying to filter the users'id, you can do
If you want to retrieve only the permissions
If you have a hasAndBelongsTo instead of a belongsTo, you can use
You can also specify the opposite relations and use If you want to write
This is not possible for many reasons, one of them being that it is ambiguous as you can't specify on what |
Ah, I see. Perhaps starting at the Opposite end of the relation would make a bit more sense. And would at least provide enough information to some kind of sugar syntax.
Or something to that effect. just spit-balling. I'm coming from the Django world and missing some of the relationship magic. this syntax throws an error every time:
User.getJoin(...) is not a function Thanks. |
Just to be clear, If User was indeed a document, please how you created your models/relations. |
Yes, models
|
This works for me:
|
Hmm. that helps a little bit. But gives an array of arrays.
Were I just want to get an unique set of permissions.
Probably just me not knowing the reql language very well. But I got pretty close by doing this.
But I can't seem to use Sorry if I'm talking in circles on this one. |
I'm not sure what you executed, but this code:
Prints
My guess is that when you copied my script, you used map instead of concatMap. Also you can just add a |
Ya, you're right I, missed a line when I copied. Thanks |
Glad we got it to work :) |
So if I actually want to get model instances back from that I would need to start from the other end of the relation and do something like
Is the an efficient way to do this? Is there a better way? |
@esatterwhite I don't think there would be a way to do this in the query. If you call |
You could do the reduction client-side, which might look something like this: Permission.getJoin({groups: {users: true}}).run().then(function (permissions) {
return permissions.reduce(function (all, doc) {
return all.concat(doc, doc.groups, doc.groups.map(function (group) {
return group.user;
}))
}, [])
}); |
I actually got run() to work and return instances as long as I can surface the field names as top level keys. That part actually works. It just the filtering that I'm having trouble with |
So there's no external API now (there used to be an internal API, but I think I removed it a long time ago), but you can do
|
This really may be more of a question, but How do you get at relations of relations, etc.
I suppose the classic example here could be a
User
belongs to manyGroups
, andGroups
have manyPermissions
.I want to get all of the
Permissions
for userX
.Aside from a brute force nested for loop, Does thinky support this?
The text was updated successfully, but these errors were encountered: