Skip to content

Refactor join query generation - #4156

Merged
janmeier merged 2 commits into
masterfrom
feat-include-limit
Jul 22, 2015
Merged

janmeier merged 2 commits into
masterfrom
feat-include-limit

Conversation

@mickhansen

Copy link
Copy Markdown
Contributor

No description provided.

@mickhansen
mickhansen force-pushed the feat-include-limit branch from 9cd7d61 to 9e104ea Compare July 21, 2015 10:35
@mickhansen
mickhansen force-pushed the feat-include-limit branch from 1775330 to 99e915b Compare July 21, 2015 12:01
@mickhansen mickhansen mentioned this pull request Jul 21, 2015
1 of 6 tasks
@mickhansen

Copy link
Copy Markdown
Contributor Author

Hmm, so limiting a include might only be possible in postgres since postgres is the only dialect to support LATERAL JOIN's that let you reference the main table from a join.

@bretmattingly

Copy link
Copy Markdown

Damn. I thought I was able to do this by setting subQuery: false but it turns out I was incorrect.

@mickhansen

Copy link
Copy Markdown
Contributor Author

@bomattin Huh?

@bretmattingly

Copy link
Copy Markdown

In order to filter on includes AND limit on the main model, we had to call our finder with subQuery: false. I was thinking that this would work for the reverse and allow limiting on includes, but I did some testing on it and wasn't able to get the query I needed.

@mickhansen

Copy link
Copy Markdown
Contributor Author

@bomattin It wouldn't work because of cartesian products. If you have two products with 3 tags each you get 6 rows, and LIMIT 4 would just result in one product missing tags.

My thought was initially to limit in a subquery, but doesn't look like it's possible to reference the main table from a subquery used in a join.

@bretmattingly

Copy link
Copy Markdown

@mickhansen Can you post a test query you're trying to generate? I think I'm coming to the same conclusion you are but just want to be certain.

@mickhansen

Copy link
Copy Markdown
Contributor Author

@bomattin I'm only researching atm but looking to execute something like LEFT JOIN (SELECT * FROM [relationTable] WHERE [relationTable].foreign_key = [mainTable].id LIMIT 3) ON ... but pretty sure it's illegal (haven't run it yet though).

@mickhansen mickhansen changed the title WIP: include.limit Refactor join query generation Jul 21, 2015
@mickhansen mickhansen added type: refactor DEPRECATED: replace with the "meta" issue type pr labels Jul 21, 2015

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can identifier and foreignIdentifier be remove completely?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bit more work, but in time yes.

janmeier added a commit that referenced this pull request Jul 22, 2015
@janmeier
janmeier merged commit 7e5b7c5 into master Jul 22, 2015
@janmeier

Copy link
Copy Markdown
Member

Sweetness!

@janmeier
janmeier deleted the feat-include-limit branch May 16, 2016 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor DEPRECATED: replace with the "meta" issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants