Arbitrary JOIN with include
See original GitHub issueI 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:
- Created 7 years ago
- Comments:19 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
where Document is not associated, but the JOIN still works as long as you provide
on
andas
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.