Skip to content

Automatic join aliases, relationship filters, and cleanup#1191

Merged
lgebhardt merged 6 commits intomasterfrom
join_tree
Jan 3, 2019
Merged

Automatic join aliases, relationship filters, and cleanup#1191
lgebhardt merged 6 commits intomasterfrom
join_tree

Conversation

@lgebhardt
Copy link
Copy Markdown
Contributor

This solves a nagging issue of how to handle tracking aliases for arbitrarily deep joins. This is needed to allow filtering based on the joined tables.

The aliases are determined by building up the required joins one level at a time and noting the nodes added to the relation. To handle joins that may be added twice the JoinTree class is introduced and allows the tracking of the required joins and handles consolidating duplicate joins, say from two filters on the same related table.

This also removes some custom sql that was used for left joins. This is now using the left_join method that's in rails 5. This will require a gem to add this functionality to rails 4 projects. The left_join gem has been tested, and seems to work well.

Adds support for relationship filters.

All Submissions:

  • I've checked to ensure there aren't other open Pull Requests for the same update/change.
  • I've submitted a ticket for my issue if one did not already exist.
  • My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
  • I've used Github auto-closing keywords in the commit message or the description.
  • I've added/updated tests for this change.

New Feature Submissions:

  • I've submitted an issue that describes this feature, and received the go ahead from the maintainers.
  • My submission includes new tests.
  • My submission maintains compliance with JSON:API.

Bug fixes and Changes to Core Features:

  • I've included an explanation of what the changes do and why I'd like you to include them.
  • I've provided test(s) that fails without the change.

Test Plan:

Reviewer Checklist:

  • Maintains compliance with JSON:API
  • Adequate test coverage exists to prevent regressions

@lgebhardt lgebhardt mentioned this pull request Jan 2, 2019
12 tasks
Comment thread test/controllers/controller_test.rb Outdated

def test_pictures_index_with_polymorphic_include_one_level
assert_cacheable_get :index, params: {include: 'imageable'}
get :index, params: {include: 'imageable'}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

revert to assert_cacheable_get for consistency

merge(Book.not_banned)
},
class_name: 'Book',
join_table: :book_authors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check spacing

* enables related resource filtering
* introduces JoinTree to track the required joins for a request to avoid
join collisions
* simplifies the resource finder, but there's still some room for improvement
* makes use of the rails 5 `left_join` method. For rails 4 will require
an additional gem to add the functionality. This is tested with the
`left_join` gem, though others could exist and work.
Copy link
Copy Markdown
Contributor

@dgeb dgeb left a comment

Choose a reason for hiding this comment

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

Looks good now. I like the renamed relation_join_hash.

@lgebhardt lgebhardt merged commit 398df59 into master Jan 3, 2019
@lgebhardt lgebhardt deleted the join_tree branch February 11, 2019 22:55
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

Successfully merging this pull request may close these issues.

2 participants