Skip to content

Commit

Permalink
Bump to 2.0: Pull original fork master (rzane's fork) (#3)
Browse files Browse the repository at this point in the history
* Find the table

* Use polyamorous from master

* With activerecord-hackery/ransack#1004, all but
one polymorphism test is fixed.

There are still several failures. Basically, any test that does an outer
join is still doing an inner join.

* Explain how this is completely broken

* Add byebug for development/testing

* Have Active Record build tables for their aliases

This may help with rzane#97.

* Fix test for equivalent logic

The new version of Active Record or Polyamorous seems to switch the
order of these two SQL conditions, but the new statement is logically
equivalent to the old one.

* Use `variants` for SQL snapshot change

* Make it possible to get good polymorphic joins

Actually getting polymorphic joins to work correctly will require
either explicitly specifying the master branch of the `ransack`
project (commit c9cc20de9e0f or something with equivalent
functionality) in the project `Gemfile` or the `ransack` project
releasing a new 2.x (> 2.3.2) version with that functionality.

Addresses most of the Active Record 5.2.x (>= 5.2.1) problems in
rzane#97.  The only remaining issues are around inner
joins after left joins.

* Track all associations used to find correct alias

By tracking the associations accumulated within an expression, we
can best even Active Record's own `#where` method's ability to
correctly set conditions on column values via associations.

* Reimplement #find_join_association iteratively

Replacing recursive method calls with plain iteration is almost
certainly more performant.

* Revert unnecessary changes from commit 90e02e2

* Lock down the supported versions of ActiveRecord

* Update rspec, rake, and sqlite3

* Run against Ruby 2.6

* Drop support for Active Record versions that have reached EOL

* Remove old variants

* Remove broken image from the readme

* Install latest bundler

* Explicit require test dependencies

* Remove filewatcher

* Run on GitHub actions

* Require coveralls

* Run as a matrix

* Share the environment variables

* Use the coveralls action

* Not sure what is going on here...

* Run against 5.2.0 and 5.2.5

* Give each job a name

* Remove coverage

* Mark failing tests as pending

* Get 5.2.0 passing again

* Remove coverage

* Bump

* Merge `join_dependency` back into this project, because my dreams did not really come true

* Fix checking for version as string

* Add changes from 1.4.0.beta1 to CHANGELOG.md

* Build pull requests

* remove old code from activerecord < 5.2

* removed BabySqueel::Pluck

* reduce complexety after merging `join_dependency` back into this project

* Fix table alias when joining a polymorphic table twice (rzane#108)

* Update changelog for v1.4.0

* Bump version to v1.4.0

* Tidy up version comparison code

* Bump version to v1.4.1

* add support for activerecord 6.0

* add support for activerecord 6.1

* speed up BabySqueel::ActiveRecord::VersionHelper

* add support for activerecord 7.0

* update .github/workflows/build.yml to test rails 7.0 and ruby 3.0 / 3.1

* Apply version-specific monkey-patches outside of the method definition

* Update changelog for v1.4.2

* v1.4.2

* ISSUE-117: left_joins performs INNER JOIN with ActiveRecord 6.1.4.4

* Update changelog for 1.4.3 release

* Bump to v1.4.3

* ISSUE-119: Nested merge-joins query causes NoMethodError with ActiveRecord 6.1.4.4 rzane#119

* Prepare v1.4.4

* ISSUE-121: Drop support for ActiveRecord older than 6.0

* AR 6.1: fix - FrozenError: can't modify frozen object: []

* Bump v2.0.0

Co-authored-by: Ray Zane <[email protected]>
Co-authored-by: Richard Weeks <[email protected]>
Co-authored-by: Jonas S <[email protected]>
  • Loading branch information
4 people authored Sep 6, 2022
1 parent a71a462 commit 12d7421
Show file tree
Hide file tree
Showing 43 changed files with 638 additions and 513 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
name: Active Record ${{ matrix.activerecord }} on ruby ${{ matrix.ruby }} (compat=${{ matrix.compat }})
strategy:
matrix:
activerecord: ["~> 6.0", "~> 6.1", "~> 7.0"]
compat: ["0", "1"]
ruby: [ "2.6", "2.7", "3.0", "3.1"]
exclude:
- activerecord: "~> 7.0"
ruby: "2.6"
env:
AR: ${{ matrix.activerecord }}
COMPAT: ${{ matrix.compat }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Install packages
run: sudo apt-get install libsqlite3-dev

- name: Install bundler
run: gem install bundler

- name: Install dependencies
run: bundle install

- name: Test
run: bundle exec rspec
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/pkg/
/spec/reports/
/tmp/
.byebug_history
.idea/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

118 changes: 109 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,145 +1,246 @@
## [Unreleased]

Nothing to see here.
- AR 6.1: fix - FrozenError: can't modify frozen object: []
- Drop support for ActiveRecord older than 6.0.

## [1.4.4] - 2022-02-07

### Fixed

- Nested merge-joins query causes NoMethodError with ActiveRecord 6.1.4.4 (#119)

## [1.4.3] - 2022-02-04

### Fixed

- ActiveRecord::Relation#left_joins performs INNER JOIN on Active Record 6.1 (#118)

## [1.4.2] - 2022-01-24

### Fixed

- Added support for activerecord 7.0 (#116)
- Added support for activerecord 6.1 (#116)
- Added support for activerecord 6.0 (#116)

## [1.4.1] - 2021-06-17

### Fixed

- Fixed a bug related to checking the Active Record version.

## [1.4.0] - 2021-06-17

### Fixed

- Fix table alias when joining a polymorphic table twice (#108)
- Removed internal class `BabySqueel::Pluck`. You can still use `plucking`. For example, `Post.joining { author }.plucking { author.name }`
- Removed old code from Active Record < 5.2
- Removed dependency `join_dependency`

## [1.4.0.beta1] - 2021-04-21

### Fixed

- Add Support for activerecord '>= 5.2.3'
- Drop Support for Active Record versions that have reached EOL (activerecord < 5.2)
- Use polyamorous from ransack '~> 2.3'

## [1.3.1] - 2018-05-15
## Fixed

### Fixed

- Upgraded `join_dependency` requirement, which fixes [issue #1](https://github.com/rzane/join_dependency/issues/1).

## [1.3.0] - 2018-05-04
## Added

### Added

- The ability to use `plucking` with an array of nodes. For example, `User.plucking { [id, name] }`.

## [1.2.1] - 2018-04-25
## Fixed

### Fixed

- Added support for Active Record 5.2

## [1.2.0] - 2017-10-20

### Added

- `reordering`, which is just a BabySqueel version of Active Record's `reorder`.
- `on` expressions can now be given a block that will yield the current node (#77).

## [1.1.5] - 2017-05-26

### Fixed

- Returning an empty hash from a `where.has {}` block would generate invalid SQL (#69).

## [1.1.4] - 2017-04-13

### Fixed

- Nodes::Attribute#in and #not_in generate valid SQL when given ActiveRecord::NullRelations.

## [1.1.3] - 2017-03-31

### Fixed

- Nodes::Attribute#in was not returning BabySqueel node. As a result, you couldn't chain on it. This fixes #61.

## [1.1.2] - 2017-03-21

### Fixed

- Check if a reflection has a parent reflection before comparing them. This fixes #56.

### Refactored

- The logic encapsulated in `#method_missing` and `#respond_to_missing?` was difficult to follow, because it was falling back to `super`, sometimes going up the inheritance tree multiple levels. The addition of `BabySqueel::Resolver` now handles this a little more gracefully.

## [1.1.1] - 2017-02-14

### Fixed

- There is a bug in Active Record where the `AliasTracker` initializes `Arel::Table`s use the wrong `type_caster`. To address this, BabySqueel must re-initialize the `Arel::Table` with the correct `type_caster` (#54).

## [1.1.0] - 2017-02-10

> This version drops support for Active Record 4.1. If you're stil on 4.1, you should seriously consider upgrading to at least 4.2.
### Added

- DSLs for ActiveRecord::Relation::Calculations. You can now use `plucking`, `counting`, `summing`, `averaging`, `minimizing`, and `maximizing`.

## [1.0.3] - 2017-02-09

### Added

- Support for `pluck`.
- Support for `not_in`.

## [1.0.2] - 2017-02-07

### Added

- `BabySqueel::Association` now has `#==` and `#!=`. This is only supported for Rails 5+. Example: `Post.where { author: Author.last }`.

### Fixed

- Incorrect alias detection caused by not tracking the full path to a join (#37).

## [1.0.1] - 2016-11-07

### Added
- Add DSL#_ for wrapping expressions in Arel::Node::Grouping. Thanks to [@odedniv].

- Add DSL#\_ for wrapping expressions in Arel::Node::Grouping. Thanks to [@odedniv].

### Fixed

- Use strings for attribute names like Rails does. Symbols were preventing things like `unscope` from working. Thanks to [@chewi].
- `where.has {}` will now accept `nil`.
- Arel::Nodes::Function did not previously include Arel::Math, so now you can do math operations on the result of SQL functions.
- Arel::Nodes::Binary did not previously include Arel::AliasPredication. Binary nodes can now be aliased using `as`.

## [1.0.0] - 2016-09-09

### Added
- Polyamorous. Unfortunately, this *does* monkey-patch Active Record internals, but there just isn't any other reliable way to generate outer joins. Baby Squeel, itself, will still keep monkey patching to an absolute minimum.

- Polyamorous. Unfortunately, this _does_ monkey-patch Active Record internals, but there just isn't any other reliable way to generate outer joins. Baby Squeel, itself, will still keep monkey patching to an absolute minimum.
- Within DSL blocks, you can use `exists` and `not_exists` with Active Record relations. For example: `Post.where.has { exists Post.where(title: 'Fun') }`.`
- Support for polymorphic associations.

### Deprecations

- Removed support for Active Record 4.0.x

### Changed

- BabySqueel::JoinDependency is no longer a class responsible for creating Arel joins. It is now a namespace for utilities used when working with the ActiveRecord::Association::JoinDependency class.
- BabySqueel::Nodes::Generic is now BabySqueel::Nodes::Node.
- Arel nodes are only extended with the behaviors they need. Previously, all Arel nodes were being extended with `Arel::AliasPredication`, `Arel::OrderPredications`, and `Arel::Math`.

### Fixed

- Fixed deprecation warnings on Active Record 5 when initializing an Arel::Table without a type caster.
- No more duplicate joins. Previously, Baby Squeel did a very poor job of ensuring that you didn't join an association twice.
- Alias detection should now *actually* work. The previous implementation was naive.
- Alias detection should now _actually_ work. The previous implementation was naive.

## [0.3.1] - 2016-08-02

### Added

- Ported backticks and #my from Squeel

### Changed

- DSL#sql now returns a node wrapped in a BabySqueel proxy.

## [0.3.0] - 2016-06-26

### Added

- Added Squeel compatibility mode that allows `select`, `order`, `joins`, `group`, `where`, and `having` to accept DSL blocks.
- Added the ability to query tables that aren't backed by Active Record models.
- Added `BabySqueel::[]`, which provides a `BabySqueel::Relation` for models, or a `BabySqueel::Table` for symbols/strings.

### Changed

- Renamed `BabySqueel::Association::AliasingError` to `BabySqueel::AssociationAliasingError`.

## [0.2.2] - 2016-03-30

### Added

- Support for `group` (`grouping`) and `having` (`when_having`).
- Support for sifters.
- Added `quoted` and `sql` helpers for quoting strings and SQL literals.
- More descriptive error messages when a column or association is not found.

### Fixed

- `Arel::Nodes::Grouping` does not include `Arel::Math`, so operations like `(id + 5) + 3` would fail unexpectedly.
- Fix missing bind values When joining through associations with default scope.
- Removed `ActiveRecord::VERSION` specific handling of the `WhereChain`.

## [0.2.1] - 2016-03-27

### Added

- Support for subqueries.

### Fixed

- Some Arel nodes did not have access to `as` expressions.

## [0.2.0] - 2016-03-25

### Added

- References to aliased joins in a `select`, `where`, or `order` expression now use the aliased table name.

### Changed

- Rely on `ActiveRecord::Relation#join_sources` for the implicit construction of join nodes, rather than using the `ActiveRecord::Associations::JoinDependency` directly.

### Fixed

- Associations referencing the same table weren't being aliased.

## [0.1.0] - 2016-03-16

### Added

- Initial support for selects, orders, wheres, and joins.

[Unreleased]: https://github.com/rzane/baby_squeel/compare/v1.3.1...HEAD
[unreleased]: https://github.com/rzane/baby_squeel/compare/v1.4.4...HEAD
[1.4.4]: https://github.com/rzane/baby_squeel/compare/v1.4.3...v1.4.4
[1.4.3]: https://github.com/rzane/baby_squeel/compare/v1.4.2...v1.4.3
[1.4.2]: https://github.com/rzane/baby_squeel/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/rzane/baby_squeel/compare/v1.4.0...v1.4.1
[1.4.0]: https://github.com/rzane/baby_squeel/compare/v1.4.0.beta1...v1.4.0
[1.4.0.beta1]: https://github.com/rzane/baby_squeel/compare/v1.3.1...v1.4.0.beta1
[1.3.1]: https://github.com/rzane/baby_squeel/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/rzane/baby_squeel/compare/v1.2.1...v1.3.0
[1.2.1]: https://github.com/rzane/baby_squeel/compare/v1.2.0...v1.2.1
Expand All @@ -159,6 +260,5 @@ Nothing to see here.
[0.2.2]: https://github.com/rzane/baby_squeel/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/rzane/baby_squeel/compare/v0.1.0...v0.2.0

[@chewi]: https://github.com/chewi
[@odedniv]: https://github.com/odedniv
20 changes: 18 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ gemspec
case ENV.fetch('AR', 'latest')
when 'latest'
gem 'activerecord'
gem 'sqlite3', '~> 1.4'
when 'master'
gem 'activerecord', github: 'rails/rails'
gem 'sqlite3', '~> 1.4'
else
gem 'activerecord', ENV['AR']

gem 'sqlite3', '~> 1.4'
end

case ENV.fetch('RANSACK', 'latest')
when 'latest'
gem 'ransack', require: false
when 'master'
gem 'ransack', github: 'activerecord-hackery/ransack', require: false
else
ENV['RANSACK'].split('#').tap do |repo, branch|
opts = {git: repo, require: false}
opts[:branch] = branch if branch
gem 'ransack', opts
end
end

gem 'bump'

group :test do
gem 'pry'
gem 'coveralls'
gem 'simplecov'
gem 'filewatcher'
gem 'byebug'
end
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require 'minitest/autorun'

gemfile true do
source 'https://rubygems.org'
gem 'activerecord', '~> 5.0.0' # which Active Record version?
gem 'activerecord', '~> 6.0.0' # which Active Record version?
gem 'sqlite3'
gem 'baby_squeel', github: 'rzane/baby_squeel'
end
Expand Down
Loading

0 comments on commit 12d7421

Please sign in to comment.