join-monster
join-monster copied to clipboard
1-to-1 Join
Hi,
first thanks for join-monster, really helping a lot!
What I missed so far in the docs is how to handle 1-to-1 joins between tables, probably as an INNER JOIN, maybe LEFT JOIN.
My understanding so far is that I could create a new GraphQL Object. However this leaves me with a new unneeded object in the code and in the response, which could be just flat.
So far I've solved it by using a VIEW, but I'd prefer to keep those joins in purely the code.
Is there a way I have missed?
In my case I can not use VIEWS and even if I could, it's the opposite way of what this library is doing. With VIEW you are JOINing tables even in cases when you don't need that data.
There is one more way you can solve this:
// One object using two tables
OneObject: {
sqlTable: 'parent_table',
uniqueKey: 'id',
fields: {
localField: {
// using first table - parent_table
sqlColumn: 'some_column'
}
remoteField: {
// using second table - remote_table
sqlExpr: parentTable => `(SELECT remote_column FROM remote_table WHERE ${parentTable}.join_column = remote_table.join_column)`
}
}
}
But I agree it's not ideal and JOIN would probably perform faster.
Good point - I'll give it a try.
Though I'd really like to see a possibility to do a 1-1 join more elegant.
Same problem is discussed here: #227, #198
Please join the discussion on this wiki page where we can lay down how this API should look like.
Closing as marked as duplicate