ransack 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.github/workflows/test.yml +10 -22
 - data/CHANGELOG.md +21 -0
 - data/docs/docs/getting-started/using-predicates.md +1 -1
 - data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
 - data/docs/docs/going-further/merging-searches.md +1 -1
 - data/docs/docs/going-further/polymorphic-search.md +40 -0
 - data/docs/docs/going-further/wiki-contributors.md +1 -1
 - data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
 - data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
 - data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
 - data/lib/ransack/version.rb +1 -1
 - data/ransack.gemspec +1 -1
 - metadata +9 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9db4893295fd342185cf668f2b3edbc59f1e649945024147778bdc52978e53fa
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9f57ba51a61d63f1f4023735d8a2ef9384e7840461af65169f4c0214f4b619a8
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 625d61491c96bd319e95d65d0d704f3906b8087e21f8fd2f8f2d1515ac4debdd3e39b678bbea8f0d39d6a5e58d5b46ba66919cb8b4770c8bb7fc4a77421c743e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cec0aa2875df4b9b8d5e8ae222fba9970ec0aaaf66de05ae21110a981828704a294f8f16fb55037ea0db39429611d7ea0e5f5d4ff51dbcd01cd66fca171b4ecf
         
     | 
    
        data/.github/workflows/test.yml
    CHANGED
    
    | 
         @@ -11,17 +11,13 @@ jobs: 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  fail-fast: false
         
     | 
| 
       12 
12 
     | 
    
         
             
                  matrix:
         
     | 
| 
       13 
13 
     | 
    
         
             
                    rails:
         
     | 
| 
       14 
     | 
    
         
            -
                      - v7.0. 
     | 
| 
       15 
     | 
    
         
            -
                      - v6.1. 
     | 
| 
      
 14 
     | 
    
         
            +
                      - v7.0.2
         
     | 
| 
      
 15 
     | 
    
         
            +
                      - v6.1.5
         
     | 
| 
       16 
16 
     | 
    
         
             
                      - v6.0.4
         
     | 
| 
       17 
     | 
    
         
            -
                      - 6-0-stable
         
     | 
| 
       18 
17 
     | 
    
         
             
                    ruby:
         
     | 
| 
      
 18 
     | 
    
         
            +
                      - 3.1.1
         
     | 
| 
       19 
19 
     | 
    
         
             
                      - 3.0.2
         
     | 
| 
       20 
20 
     | 
    
         
             
                      - 2.7.4
         
     | 
| 
       21 
     | 
    
         
            -
                      - 2.6.7
         
     | 
| 
       22 
     | 
    
         
            -
                    exclude:
         
     | 
| 
       23 
     | 
    
         
            -
                      - rails:  v7.0.0
         
     | 
| 
       24 
     | 
    
         
            -
                        ruby:   2.6.7
         
     | 
| 
       25 
21 
     | 
    
         
             
                env:
         
     | 
| 
       26 
22 
     | 
    
         
             
                  DB: sqlite3
         
     | 
| 
       27 
23 
     | 
    
         
             
                  RAILS: ${{ matrix.rails }}
         
     | 
| 
         @@ -42,17 +38,13 @@ jobs: 
     | 
|
| 
       42 
38 
     | 
    
         
             
                  fail-fast: false
         
     | 
| 
       43 
39 
     | 
    
         
             
                  matrix:
         
     | 
| 
       44 
40 
     | 
    
         
             
                    rails:
         
     | 
| 
       45 
     | 
    
         
            -
                      - v7.0. 
     | 
| 
       46 
     | 
    
         
            -
                      - v6.1. 
     | 
| 
      
 41 
     | 
    
         
            +
                      - v7.0.2
         
     | 
| 
      
 42 
     | 
    
         
            +
                      - v6.1.5
         
     | 
| 
       47 
43 
     | 
    
         
             
                      - v6.0.4
         
     | 
| 
       48 
     | 
    
         
            -
                      - 6-0-stable
         
     | 
| 
       49 
44 
     | 
    
         
             
                    ruby:
         
     | 
| 
      
 45 
     | 
    
         
            +
                      - 3.1.1
         
     | 
| 
       50 
46 
     | 
    
         
             
                      - 3.0.2
         
     | 
| 
       51 
47 
     | 
    
         
             
                      - 2.7.4
         
     | 
| 
       52 
     | 
    
         
            -
                      - 2.6.7
         
     | 
| 
       53 
     | 
    
         
            -
                    exclude:
         
     | 
| 
       54 
     | 
    
         
            -
                      - rails:  v7.0.0
         
     | 
| 
       55 
     | 
    
         
            -
                        ruby:   2.6.7
         
     | 
| 
       56 
48 
     | 
    
         
             
                env:
         
     | 
| 
       57 
49 
     | 
    
         
             
                  DB: mysql
         
     | 
| 
       58 
50 
     | 
    
         
             
                  RAILS: ${{ matrix.rails }}
         
     | 
| 
         @@ -82,17 +74,13 @@ jobs: 
     | 
|
| 
       82 
74 
     | 
    
         
             
                  fail-fast: false
         
     | 
| 
       83 
75 
     | 
    
         
             
                  matrix:
         
     | 
| 
       84 
76 
     | 
    
         
             
                    rails:
         
     | 
| 
       85 
     | 
    
         
            -
                      - v7.0. 
     | 
| 
       86 
     | 
    
         
            -
                      - v6.1. 
     | 
| 
      
 77 
     | 
    
         
            +
                      - v7.0.2
         
     | 
| 
      
 78 
     | 
    
         
            +
                      - v6.1.5
         
     | 
| 
       87 
79 
     | 
    
         
             
                      - v6.0.4
         
     | 
| 
       88 
     | 
    
         
            -
                      - 6-0-stable
         
     | 
| 
       89 
80 
     | 
    
         
             
                    ruby:
         
     | 
| 
      
 81 
     | 
    
         
            +
                      - 3.1.1
         
     | 
| 
       90 
82 
     | 
    
         
             
                      - 3.0.2
         
     | 
| 
       91 
83 
     | 
    
         
             
                      - 2.7.4
         
     | 
| 
       92 
     | 
    
         
            -
                      - 2.6.7
         
     | 
| 
       93 
     | 
    
         
            -
                    exclude:
         
     | 
| 
       94 
     | 
    
         
            -
                      - rails:  v7.0.0
         
     | 
| 
       95 
     | 
    
         
            -
                        ruby:   2.6.7
         
     | 
| 
       96 
84 
     | 
    
         
             
                env:
         
     | 
| 
       97 
85 
     | 
    
         
             
                  DB: postgres
         
     | 
| 
       98 
86 
     | 
    
         
             
                  RAILS: ${{ matrix.rails }}
         
     | 
| 
         @@ -135,7 +123,7 @@ jobs: 
     | 
|
| 
       135 
123 
     | 
    
         
             
                  - name: Set up Ruby
         
     | 
| 
       136 
124 
     | 
    
         
             
                    uses: ruby/setup-ruby@v1
         
     | 
| 
       137 
125 
     | 
    
         
             
                    with:
         
     | 
| 
       138 
     | 
    
         
            -
                      ruby-version: 3. 
     | 
| 
      
 126 
     | 
    
         
            +
                      ruby-version: 3.1.1
         
     | 
| 
       139 
127 
     | 
    
         
             
                  - name: Install dependencies
         
     | 
| 
       140 
128 
     | 
    
         
             
                    run: bundle install
         
     | 
| 
       141 
129 
     | 
    
         
             
                  - name: Run bug report templates
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -2,6 +2,27 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            ## Unreleased
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
            ## 3.1.0 - 2022-04-21
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            * Fix predicate name in "Using Predicates" documentation page.
         
     | 
| 
      
 8 
     | 
    
         
            +
              PR [1313](https://github.com/activerecord-hackery/ransack/pull/1313)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            * Drop Ruby 2.6 support.
         
     | 
| 
      
 11 
     | 
    
         
            +
              PR [1311](https://github.com/activerecord-hackery/ransack/pull/1311)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            * Allow Ransack to be used with Rails 7.1.0.alpha.
         
     | 
| 
      
 14 
     | 
    
         
            +
              PR [1309](https://github.com/activerecord-hackery/ransack/pull/1309)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            * Put contributor list last in documentation site.
         
     | 
| 
      
 17 
     | 
    
         
            +
              PR [1308](https://github.com/activerecord-hackery/ransack/pull/1308)
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            * Add `acts-as-taggable-on` and polymorphic searches to documentation.
         
     | 
| 
      
 20 
     | 
    
         
            +
              PR [1306](https://github.com/activerecord-hackery/ransack/pull/1306)
         
     | 
| 
      
 21 
     | 
    
         
            +
              PR [1312](https://github.com/activerecord-hackery/ransack/pull/1312)
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            * Add full link to issue about merging searches to documentation.
         
     | 
| 
      
 24 
     | 
    
         
            +
              PR [1305](https://github.com/activerecord-hackery/ransack/pull/1305)
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       5 
26 
     | 
    
         
             
            ## 3.0.1 - 2022-04-08
         
     | 
| 
       6 
27 
     | 
    
         | 
| 
       7 
28 
     | 
    
         
             
            * Fix `:data` option to `sort_link` being incorrectly appended to the generated
         
     | 
| 
         @@ -23,7 +23,7 @@ You can also combine predicates for OR queries: 
     | 
|
| 
       23 
23 
     | 
    
         
             
            The syntax for `OR` queries on an associated model is not immediately obvious, but makes sense. Assuming a `User` `has_one` `Account` and the `Account` has `attributes` `foo` and `bar`:
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
            ```ruby
         
     | 
| 
       26 
     | 
    
         
            -
            >> User.ransack( 
     | 
| 
      
 26 
     | 
    
         
            +
            >> User.ransack(account_foo_or_account_bar_cont: 'val').result.to_sql
         
     | 
| 
       27 
27 
     | 
    
         
             
            => SELECT "users".* FROM "users" INNER JOIN accounts ON accounts.user_id = users.id WHERE ("accounts.foo LIKE '%val%' OR accounts.bar LIKE '%val%')
         
     | 
| 
       28 
28 
     | 
    
         
             
            ```
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
         @@ -0,0 +1,114 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            title: Acts-as-taggable-on
         
     | 
| 
      
 3 
     | 
    
         
            +
            sidebar_position: 13
         
     | 
| 
      
 4 
     | 
    
         
            +
            ---
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            ## Using Acts As Taggable On
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            If you have an `ActiveRecord` model and you're using [acts-as-taggable-on](https://github.com/mbleigh/acts-as-taggable-on),
         
     | 
| 
      
 9 
     | 
    
         
            +
            chances are you might want to search on tagged fields. Follow the instructions to install the gem and then set up your project files.
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ### Configure the model
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            `app/models/tasks.rb`
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            You can call the tagging field anything you like, it just needs to be plural. No migration is needed as this is stored in the internal ActsAsTaggable tables (`tags` and `taggings`).
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 18 
     | 
    
         
            +
            class Task < ApplicationRecord
         
     | 
| 
      
 19 
     | 
    
         
            +
              acts_as_taggable_on :projects
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
      
 21 
     | 
    
         
            +
            ```
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ### Controller
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            Add a field to strong params in the controller. Use the singular name with `_list`.
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            `app/controllers/tasks_controller.rb`
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 30 
     | 
    
         
            +
            def strong_params
         
     | 
| 
      
 31 
     | 
    
         
            +
              params
         
     | 
| 
      
 32 
     | 
    
         
            +
                .require(:tasks)
         
     | 
| 
      
 33 
     | 
    
         
            +
                .permit(:task, :example_field, :project_list)
         
     | 
| 
      
 34 
     | 
    
         
            +
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ### Form
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            We need to `send` the tag fieldname to our model, also using the singular naming.
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            ```
         
     | 
| 
      
 41 
     | 
    
         
            +
            <div class='form-group'>
         
     | 
| 
      
 42 
     | 
    
         
            +
              <%= f.label :project_list %>
         
     | 
| 
      
 43 
     | 
    
         
            +
              <%= f.text_field :project_list, value: @task.send(:project_list).to_s %>
         
     | 
| 
      
 44 
     | 
    
         
            +
             </div>
         
     | 
| 
      
 45 
     | 
    
         
            +
            ```
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            Now we can collect our data via the form, with tags separated by commas.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ## Ransack Search
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            Imagine you have the following two instances of `Task`:
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 54 
     | 
    
         
            +
            { id: 1, name: 'Clean up my room',        projects: [ 'Home', 'Personal' ] }
         
     | 
| 
      
 55 
     | 
    
         
            +
            { id: 2, name: 'Complete math exercises', projects: [ 'Homework', 'Study' ] }
         
     | 
| 
      
 56 
     | 
    
         
            +
            ```
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            When you're writing a `Ransack` search form, you can choose any of the following options:
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            ```erb
         
     | 
| 
      
 61 
     | 
    
         
            +
            <%= search_form_for @search do |f| %>
         
     | 
| 
      
 62 
     | 
    
         
            +
              <%= f.text_field :projects_name_in   %> <!-- option a -->
         
     | 
| 
      
 63 
     | 
    
         
            +
              <%= f.text_field :projects_name_eq   %> <!-- option b -->
         
     | 
| 
      
 64 
     | 
    
         
            +
              <%= f.text_field :projects_name_cont %> <!-- option c -->
         
     | 
| 
      
 65 
     | 
    
         
            +
            <% end %>
         
     | 
| 
      
 66 
     | 
    
         
            +
            ```
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            ### Option A - Match keys exactly
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            Option `a` will match keys exactly. This is the solution to choose if you want to distinguish 'Home' from 'Homework': searching for 'Home' will return just the `Task` with id 1. It also allows searching for more than one tag at once (comma separated):
         
     | 
| 
      
 71 
     | 
    
         
            +
            - `Home, Personal` will return task 1
         
     | 
| 
      
 72 
     | 
    
         
            +
            - `Home, Homework` will return task 1 and 2
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            ### Option B - match key combinations
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            Option `b` will match all keys exactly. This is the solution if you wanna search for specific combinations of tags:
         
     | 
| 
      
 77 
     | 
    
         
            +
            - `Home` will return nothing, as there is no Task with just the `Home` tag
         
     | 
| 
      
 78 
     | 
    
         
            +
            - `Home, Personal` will return task 1
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            ### Option C - match substrings
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            Option `c` is used to match substrings. This is useful when you don't care for the exact tag, but only for part of it:
         
     | 
| 
      
 83 
     | 
    
         
            +
            - `Home` will return task 1 and 2 (`/Home/` matches both `"Home"` and `"Homework"`)
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            ### Option D - select from a list of tags
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            In Option D we allow the user to select a list of valid tags and then search againt them. We use the plural name here.
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
            ```erb
         
     | 
| 
      
 90 
     | 
    
         
            +
            <div class='form-group'>
         
     | 
| 
      
 91 
     | 
    
         
            +
              <%= f.label :projects_name, 'Project' %>
         
     | 
| 
      
 92 
     | 
    
         
            +
              <%= f.select :projects_name_in, ActsAsTaggableOn::Tag.distinct.order(:name).pluck(:name) %>
         
     | 
| 
      
 93 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 94 
     | 
    
         
            +
            ```
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            ## Multitenancy 
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            ActsAsTaggableOn allows scoping of tags based on another field on the model. Suppose we have a `language` field on the model, as an effective second level key. We would adjust our model to look like this:
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 101 
     | 
    
         
            +
            class Task < ApplicationRecord
         
     | 
| 
      
 102 
     | 
    
         
            +
              acts_as_taggable_on :projects
         
     | 
| 
      
 103 
     | 
    
         
            +
              acts_as_taggable_tenant :language
         
     | 
| 
      
 104 
     | 
    
         
            +
            end
         
     | 
| 
      
 105 
     | 
    
         
            +
            ```
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            The Ransack search is then filtered using the `for_tenant` method
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
            ```
         
     | 
| 
      
 110 
     | 
    
         
            +
            <div class='form-group'>
         
     | 
| 
      
 111 
     | 
    
         
            +
              <%= f.label :projects_name, 'Project' %>
         
     | 
| 
      
 112 
     | 
    
         
            +
              <%= f.select :projects_name_in, ActsAsTaggableOn::Tag.for_tenant('fr').distinct.order(:name).pluck(:name) %>
         
     | 
| 
      
 113 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 114 
     | 
    
         
            +
                  
         
     | 
| 
         @@ -38,4 +38,4 @@ WHERE ( 
     | 
|
| 
       38 
38 
     | 
    
         
             
            ORDER BY "people"."id" DESC
         
     | 
| 
       39 
39 
     | 
    
         
             
            ```
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
            Admittedly this is not as simple as it should be, but it's workable for now. (Implementing  
     | 
| 
      
 41 
     | 
    
         
            +
            Admittedly this is not as simple as it should be, but it's workable for now. (Implementing [issue 417](https://github.com/activerecord-hackery/ransack/issues/417) could make this more straightforward.)
         
     | 
| 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            title: Polymorphic Searches
         
     | 
| 
      
 3 
     | 
    
         
            +
            sidebar_position: 14
         
     | 
| 
      
 4 
     | 
    
         
            +
            ---
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            When making searches from polymorphic models it is necessary to specify the type of model you are searching. 
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            Given two models
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 13 
     | 
    
         
            +
            class House < ActiveRecord::Base
         
     | 
| 
      
 14 
     | 
    
         
            +
              has_one :location, as: :locatable
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            class Location < ActiveRecord::Base
         
     | 
| 
      
 18 
     | 
    
         
            +
              belongs_to :locatable, polymorphic: true
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
      
 20 
     | 
    
         
            +
            ```
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            Normally (without polymorphic relationship) you would be able to search as per below:
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 25 
     | 
    
         
            +
            Location.ransack(locatable_number_eq: 100).result
         
     | 
| 
      
 26 
     | 
    
         
            +
            ```
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            However when this is searched you will get the following error
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 31 
     | 
    
         
            +
            ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :locatable
         
     | 
| 
      
 32 
     | 
    
         
            +
            ```
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            In order to search for locations by house number when the relationship is polymorphic you have to specify the type of records you will be searching and construct your search as below:
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 37 
     | 
    
         
            +
            Location.ransack(locatable_of_House_type_number_eq: 100).result
         
     | 
| 
      
 38 
     | 
    
         
            +
            ```
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            note the `_of_House_type_` added to the search key. This allows Ransack to correctly specify the table names in SQL join queries.
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            title: Wiki Contributors
         
     | 
| 
       3 
     | 
    
         
            -
            sidebar_position:  
     | 
| 
      
 3 
     | 
    
         
            +
            sidebar_position: 20
         
     | 
| 
       4 
4 
     | 
    
         
             
            ---
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Ransack previously had documentation contained in a GitHub Wiki, and this content has been merged into this documentation website. The following long list of _amazing_ people all made contributions to the Wiki:
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'polyamorous/activerecord_6.1_ruby_2/join_association'
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'polyamorous/activerecord_6.1_ruby_2/join_dependency'
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'polyamorous/activerecord_6.1_ruby_2/reflection'
         
     | 
    
        data/lib/ransack/version.rb
    CHANGED
    
    
    
        data/ransack.gemspec
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       12 
12 
     | 
    
         
             
              s.homepage    = "https://github.com/activerecord-hackery/ransack"
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.summary     = %q{Object-based searching for Active Record.}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.description = %q{Ransack is the successor to the MetaSearch gem. It improves and expands upon MetaSearch's functionality, but does not have a 100%-compatible API.}
         
     | 
| 
       15 
     | 
    
         
            -
              s.required_ruby_version = '>= 2. 
     | 
| 
      
 15 
     | 
    
         
            +
              s.required_ruby_version = '>= 2.7'
         
     | 
| 
       16 
16 
     | 
    
         
             
              s.license     = 'MIT'
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              s.add_dependency 'activerecord', '>= 6.0.4'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ransack
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ernie Miller
         
     | 
| 
         @@ -12,7 +12,7 @@ authors: 
     | 
|
| 
       12 
12 
     | 
    
         
             
            autorequire:
         
     | 
| 
       13 
13 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       14 
14 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       15 
     | 
    
         
            -
            date: 2022-04- 
     | 
| 
      
 15 
     | 
    
         
            +
            date: 2022-04-21 00:00:00.000000000 Z
         
     | 
| 
       16 
16 
     | 
    
         
             
            dependencies:
         
     | 
| 
       17 
17 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       18 
18 
     | 
    
         
             
              name: activerecord
         
     | 
| 
         @@ -97,6 +97,7 @@ files: 
     | 
|
| 
       97 
97 
     | 
    
         
             
            - docs/docs/getting-started/sorting.md
         
     | 
| 
       98 
98 
     | 
    
         
             
            - docs/docs/getting-started/using-predicates.md
         
     | 
| 
       99 
99 
     | 
    
         
             
            - docs/docs/going-further/_category_.json
         
     | 
| 
      
 100 
     | 
    
         
            +
            - docs/docs/going-further/acts-as-taggable-on.md
         
     | 
| 
       100 
101 
     | 
    
         
             
            - docs/docs/going-further/associations.md
         
     | 
| 
       101 
102 
     | 
    
         
             
            - docs/docs/going-further/custom-predicates.md
         
     | 
| 
       102 
103 
     | 
    
         
             
            - docs/docs/going-further/documentation.md
         
     | 
| 
         @@ -107,6 +108,7 @@ files: 
     | 
|
| 
       107 
108 
     | 
    
         
             
            - docs/docs/going-further/img/create_release.png
         
     | 
| 
       108 
109 
     | 
    
         
             
            - docs/docs/going-further/merging-searches.md
         
     | 
| 
       109 
110 
     | 
    
         
             
            - docs/docs/going-further/other-notes.md
         
     | 
| 
      
 111 
     | 
    
         
            +
            - docs/docs/going-further/polymorphic-search.md
         
     | 
| 
       110 
112 
     | 
    
         
             
            - docs/docs/going-further/ransackers.md
         
     | 
| 
       111 
113 
     | 
    
         
             
            - docs/docs/going-further/release_process.md
         
     | 
| 
       112 
114 
     | 
    
         
             
            - docs/docs/going-further/saving-queries.md
         
     | 
| 
         @@ -147,6 +149,9 @@ files: 
     | 
|
| 
       147 
149 
     | 
    
         
             
            - lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb
         
     | 
| 
       148 
150 
     | 
    
         
             
            - lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb
         
     | 
| 
       149 
151 
     | 
    
         
             
            - lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb
         
     | 
| 
      
 152 
     | 
    
         
            +
            - lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb
         
     | 
| 
      
 153 
     | 
    
         
            +
            - lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb
         
     | 
| 
      
 154 
     | 
    
         
            +
            - lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb
         
     | 
| 
       150 
155 
     | 
    
         
             
            - lib/polyamorous/join.rb
         
     | 
| 
       151 
156 
     | 
    
         
             
            - lib/polyamorous/polyamorous.rb
         
     | 
| 
       152 
157 
     | 
    
         
             
            - lib/polyamorous/swapping_reflection_class.rb
         
     | 
| 
         @@ -246,14 +251,14 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       246 
251 
     | 
    
         
             
              requirements:
         
     | 
| 
       247 
252 
     | 
    
         
             
              - - ">="
         
     | 
| 
       248 
253 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       249 
     | 
    
         
            -
                  version: '2. 
     | 
| 
      
 254 
     | 
    
         
            +
                  version: '2.7'
         
     | 
| 
       250 
255 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       251 
256 
     | 
    
         
             
              requirements:
         
     | 
| 
       252 
257 
     | 
    
         
             
              - - ">="
         
     | 
| 
       253 
258 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       254 
259 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       255 
260 
     | 
    
         
             
            requirements: []
         
     | 
| 
       256 
     | 
    
         
            -
            rubygems_version: 3.3. 
     | 
| 
      
 261 
     | 
    
         
            +
            rubygems_version: 3.3.10
         
     | 
| 
       257 
262 
     | 
    
         
             
            signing_key:
         
     | 
| 
       258 
263 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       259 
264 
     | 
    
         
             
            summary: Object-based searching for Active Record.
         
     |