1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00
activerecord-hackery--ransack/lib
yuuji.yaginuma 5b300a839a Do not override join_constraints
In the current master, an error occurs when performing a specific
join process in AR 5.2.1(My bad!).

Reproduce script is following.

```
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", "5.2.1.rc1"
  gem "byebug"
  gem "ransack", github: "activerecord-hackery/ransack", require: false
  gem "sqlite3"
  # gem "pg"
end

require "active_record"
require "ransack"
require "minitest/autorun"
require "logger"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table "set_adopted_books", force: :cascade do |t|
    t.bigint "adopted_book_set_id"
  end

  create_table "adopted_book_sets", force: :cascade do |t|
    t.bigint "library_id"
  end

  create_table "libraries", force: :cascade do |t|
  end
end

class SetAdoptedBook < ActiveRecord::Base
  belongs_to :adopted_book_set
end

class AdoptedBookSet < ActiveRecord::Base
  belongs_to :library
  has_many   :set_adopted_books, dependent: :destroy
end

class Library < ActiveRecord::Base
end

class BugTest < Minitest::Test
  def test_association_stuff
    refute SetAdoptedBook.joins(adopted_book_set: :library).exists?
    # => ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name: libraries.id: SELECT  1 AS one FROM "set_adopted_books" INNER JOIN "adopted_book_sets" ON "adopted_book_sets"."id" = "set_adopted_books"."adopted_book_set_id" INNER JOIN "libraries" ON "libraries"."id" = "adopted_book_sets"."library_id" INNER JOIN "libraries" ON "libraries"."id" = "adopted_book_sets"."library_id" LIMIT ?
  end
end
```

ransack overrides the join process, and it is an error because there is
not enough processing there.
However, it does not seem to be necessary to override the process at the
moment. So, I removed the overriding methods.
2018-08-07 13:52:02 +09:00
..
polyamorous Do not override join_constraints 2018-08-07 13:52:02 +09:00
ransack Add support for Rails 5.2.1 2018-08-01 21:01:37 +09:00
polyamorous.rb Add support for Rails 5.2.1 2018-08-01 21:01:37 +09:00
ransack.rb ⚠️ `*' interpreted as argument prefix 2018-02-02 18:49:41 +09:00