question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arbitrary JOIN with include

See original GitHub issue

I would like to give an expression like this

documentModel.hasOne(documentModel,
{
    as: "user",
    foreignKey: "(\"user\".\"data\"#>>\'{author}\')::uuid" 
               //("user"."data"#>>'{author}')::uuid
}

The models are different kind of records but belongs to the same table (document). This table has the column “data” (type = JSONB) and the column “id” (type = uuid)

Generated join part

LEFT OUTER JOIN "document" AS "user" ON "document"."id" = "user"."(user.data#>>'{author}'):uuid" AND "user"."deletedAt" IS NULL

Expected join part

LEFT OUTER JOIN "document" AS "user" ON "document"."id" = ("user"."data"#>>'{author}')::uuid AND "user"."deletedAt" IS NULL

My idea is that we could use something like this

postModel.hasOne(userModel,
{
    as: "user",
    foreignKey: {
        literal: "(\"user\".\"data\"#>>\'{author}\')::uuid"
    }
}

If you guys could guide me into the right files to change I would appreciate to try implementing this feature. I’m kind of new in this project and I can’t understand the source code well.

Thanks !

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
felixfbeckercommented, Oct 22, 2016

It would probably be of benefit to not join just a table, but an arbitrary model (document) so you get actual instances. What do you think about this:

find({ include: [ { model: Document, as: 'user', on: literal('...') } ] })

where Document is not associated, but the JOIN still works as long as you provide on and as

1reaction
felixfbeckercommented, Oct 24, 2016

No, you can use literal. But I think we have a syntax for accessing JSON properties. We need an API proposal because software needs to be designed before it can be written 😄 I can tell you that I won’t have the time for this feature. Who ever needs it can pick it up and implement the syntax we agreed on. I also am the wrong person to ask about where in the code this needs to be implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL join arbitrary information to form a mixed list
If you want to have a result which has a variable structure, your best bet is JSON. The following query would UNION the...
Read more >
JOIN clause
The join condition may be an arbitrary Boolean expression referring to the attributes in the FROM statement. The expression must be enclosed in...
Read more >
Complex Query Operators - EF Core
Join. The LINQ Join operator allows you to connect two data sources based on the key selector for each source, generating a tuple...
Read more >
Relationships and Joins — peewee 3.15.4 documentation
Joining on arbitrary fields​​ object_id field and User.id. Rather than joining on a specific Field , we will join using an Expression ....
Read more >
ANSI JOIN Support in N1QL
Example 1: ANSI JOIN with arbitrary join condition ... Therefore it is recommended that you include filters on the right-hand side keyspace ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found