Skip to content
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

With missing if defined in sub query #717

Closed
filipagh opened this issue Apr 17, 2024 · 2 comments
Closed

With missing if defined in sub query #717

filipagh opened this issue Apr 17, 2024 · 2 comments

Comments

@filipagh
Copy link

filipagh commented Apr 17, 2024

hi maybe im not doing something wrong but i have complicated query with with defined in sub query, and compiled query is missing with part

minimal changed docs example

var activePosts = new Query("Comments")
    .Select("PostId")
    .SelectRaw("count(1) as Count")
    .GroupBy("PostId")
    .HavingRaw("count(1) > 100");

var queryWith = new Query("ActivePosts")
    .With("ActivePosts", activePosts) // now you can consider ActivePosts as a regular table in the database
    .Join("ActivePosts", "ActivePosts.PostId", "Posts.Id");
  
var query = new Query().From(queryWith); 

result :
SELECT * FROM ( SELECT * FROM [ActivePosts] INNER JOIN [ActivePosts] ON [ActivePosts].[PostId] = [Posts].[Id] )

WITH "ActivePosts" as is missing

@ahmad-moussawi
Copy link
Contributor

Here the From will not conserve the inner With, using an outer With will do.

This example should work.

var activePosts = new Query("Comments")
    .Select("PostId")
    .SelectRaw("count(1) as Count")
    .GroupBy("PostId")
    .HavingRaw("count(1) > 100");

var queryWith = new Query("ActivePosts")
    .With("ActivePosts", activePosts) // now you can consider ActivePosts as a regular table in the database
    .Join("ActivePosts", "ActivePosts.PostId", "Posts.Id");
  
var query = new Query().With("sub", queryWith).From("sub"); 

@filipagh
Copy link
Author

yes this worked, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants