aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #35503 from samjohn/cannot-grammar-correctionXavier Noria2019-03-071-1/+1
|\ | | | | Replace “can not” with “cannot”.
| * Replace “can not” with “cannot”.Samantha John2019-03-061-1/+1
| |
* | Fix incorrect identifier quoting [ci skip]Ryuta Kamizono2019-03-071-2/+2
|/
* Relax table name detection in `from` to allow any extension like INDEX hintRyuta Kamizono2019-03-011-2/+5
| | | | | | | | | | #35360 allows table name qualified if `from` has original table name. But that is still too strict. We have a valid use case that `from` with INDEX hint (e.g. `from("comments USE INDEX (PRIMARY)")`). So I've relaxed the table name detection in `from` to allow any extension like INDEX hint. Fixes #35359.
* Merge pull request #33611 from willianveiga/feature/reselect-methodAndrew White2019-03-011-0/+21
|\ | | | | Add reselect method
| * Avoid creating an extra relation instanceWillian Gustavo Veiga2018-10-241-2/+9
| |
| * Merge branch 'master' into feature/reselect-methodWillian Gustavo Veiga2018-10-221-10/+8
| |\
| * \ Merge branch 'master' into feature/reselect-methodWillian Gustavo Veiga2018-10-021-4/+4
| |\ \
| * | | Add reselect methodWillian Gustavo Veiga2018-08-131-0/+14
| | | |
* | | | Fix `pluck` and `select` with `from` if `from` has original table nameRyuta Kamizono2019-02-221-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is caused by 0ee96d1. Since #18744, `select` columns doesn't be qualified by table name if using `from`. 0ee96d1 follows that for `pluck` as well. But people depends that `pluck` columns are qualified even if using `from`. So I've fixed that to be qualified if `from` has the original table name to keep the behavior as much as before. Fixes #35359.
* | | | Fix lint `ShadowingOuterLocalVariable`soartec-lab2019-02-211-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Revert "Fix lint `ShadowingOuterLocalVariable`" This reverts commit 38bd45a48992b500478a82d56d31468a322937a8. Change of variable name Fix lint `ShadowingOuterLocalVariable`
* | | | Merge pull request #35274 from AlexBrodianoi/fix_does_not_support_reverseRyuta Kamizono2019-02-171-1/+1
|\ \ \ \ | | | | | | | | | | Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a single ordering argument.
| * | | | Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a ↵Finn Young2019-02-171-1/+1
| | | | | | | | | | | | | | | | | | | | single ordering argument.
* | | | | Fix `order` with custom attributesRyuta Kamizono2019-02-171-2/+8
|/ / / / | | | | | | | | | | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* | | / Fix `pluck` and `select` with custom attributesRyuta Kamizono2019-02-131-5/+17
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
* | | Don't expose internal `get_value`/`set_value` methodsRyuta Kamizono2018-10-181-10/+8
| |/ |/|
* | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* | Permit list usage cleanup and clearer documentationKevin Deisz2018-08-271-2/+2
| |
* | Convert over the rest of the whitelist referencesKevin Deisz2018-08-241-2/+2
|/
* Use `construct_join_dependency` in all placesRyuta Kamizono2018-07-031-3/+1
|
* Ensure to calculate column aliases after all table aliases are constructedRyuta Kamizono2018-06-191-7/+9
| | | | | | | | | | | | | | | | | Currently, column aliases which is used for eager loading are calculated before constructing all table aliases in FROM clause. `JoinDependency#join_constraints` constructs table aliases for `joins` first, and then always re-constructs table aliases for eager loading. If both `joins` and eager loading are given a same table association, the re-construction would cause the discrepancy between column aliases and table aliases. To avoid the discrepancy, the column aliases should be calculated after all table aliases are constructed. Fixes #30603.
* `get_value` needs to be a public methodGraham Turner2018-04-251-4/+5
| | | | | | Adds test case for failing issue Moves set_value back to protected
* Fix relation merging with skip_query_cache!James Williams2018-04-191-2/+2
|
* Only preload misses on multifetch cacheLachlan Sylvester2018-03-061-0/+5
|
* Merge pull request #31133 from ↵Matthew Draper2018-02-111-0/+1
|\ | | | | | | | | mohsen-alizadeh/sanitize_empty_and_nil_parameters_passed_to_select sanitize empty and nil parameters to select #31059
| * sanitize empty and nil parameters to selectMohsen Alizadeh2017-11-121-0/+1
| |
* | Fix relation merger issue with `left_outer_joins`Mehmet Emin INAC2018-01-151-0/+2
| |
* | Merge pull request #28313 from sandrew/masterRyuta Kamizono2018-01-151-2/+3
|\ \ | | | | | | | | | Allow unscoping of left_outer_joins
| * | Allow unscoping of left_outer_joinsAndrei Shaidurov2017-03-061-1/+1
| | |
* | | Don't need to pass `manager` to `convert_join_strings_to_ast`Ryuta Kamizono2018-01-141-2/+2
| | | | | | | | | | | | Because `Relation` already have Arel `table`.
* | | Partial revert the changing default value of `readonly_value`Ryuta Kamizono2018-01-051-13/+2
| | | | | | | | | | | | | | | This is a partial revert of #26182. There is no reason to change the default value.
* | | Place args normalization from `left_outer_joins` to `left_outer_joins!`Ryuta Kamizono2017-12-201-4/+2
| | | | | | | | | | | | Like other query bang methods.
* | | Using table name qualified column names unless having SELECT list explicitlyRyuta Kamizono2017-12-181-2/+2
| | | | | | | | | | | | | | | | | | Previously table name qualified `*` is used in that case. If it is not qualified with a table name, an ambiguous column name error will occur when using JOINs.
* | | Make `sanitize_sql_` methods publicyuuji.yaginuma2017-12-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Currently, sanitize methods are private. So need `send` to use from outside class. However, sometimes want to use sanitize methods from outside Class when want to generate SQL including multiple tables like search. In order to avoid using `send` in such a case, changed methods to public.
* | | Quote colum_names when building select:Edouard CHIN2017-12-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | - #30980 introcuded a change to not use `Arel.star` when model have ignored columns, a query used to look like `SELECT *. FROM developers` whereas now it would like `SELECT column1, column2 FROM developers` - If a column has the same name has a reserved database specific keyword (such as key, where ...) then the query would fail because the names aren't quoted - Quoting almost always happen unless we use a `from` clause in the query https://github.com/rails/rails/blob/9965b98dc0d58a86e10b4343bb6e15e01661a8c3/activerecord/lib/active_record/relation/query_methods.rb#L1052 - This PR cast all columns name to symbols in order for the quoting logic to be picked up https://github.com/rails/rails/blob/9965b98dc0d58a86e10b4343bb6e15e01661a8c3/activerecord/lib/active_record/relation/query_methods.rb#L1054-L1055 - A reproduction script can be found here https://gist.github.com/Edouard-chin/f56d464a0adcb76962afc1a9134a1536
* | | Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-141-1/+13
|\ \ \ | | | | | | | | | | | | Disallow raw SQL in dangerous AR methods
| * | | push order arg checks down to allow for bindsBen Toews2017-11-091-27/+6
| | | |
| * | | deal with Array arguments to #orderBen Toews2017-11-091-1/+13
| | | |
| * | | convert order arg to string before checking if we can reverse itBen Toews2017-11-091-0/+4
| | | |
| * | | use << instead of #concat in #reverse_sql_order because we might be working ↵Ben Toews2017-11-091-1/+1
| | | | | | | | | | | | | | | | with Arel SQL literator which overrides #concat
| * | | try using regexesBen Toews2017-11-091-19/+2
| | | |
| * | | allow table name and direction in string order argBen Toews2017-11-091-2/+24
| | | |
| * | | call enforce_raw_sql_whitelist on @klass so it works with FakeKlassBen Toews2017-11-091-2/+2
| | | |
| * | | work with actual string when reversing orderBen Toews2017-11-091-0/+3
| | | |
| * | | allow Arel.sql() for pluckBen Toews2017-11-091-47/+7
| | | |
| * | | add config to check arguments to unsafe AR methodsBen Toews2017-11-091-0/+49
| | | |
* | | | Merge pull request #30980 from sobrinho/sobrinho/arel-star-ignored-columnsRafael França2017-11-131-0/+2
|\ \ \ \ | |_|_|/ |/| | | Do not use `Arel.star` when `ignored_columns`
| * | | Do not use `Arel.star` when `ignored_columns`Jon Moss2017-11-131-0/+2
| |/ / | | | | | | | | | | | | | | | | | | If there are any ignored columns, we will now list out all columns we want to be returned from the database. Includes a regression test.
* | | Ensure `apply_join_dependency` for subqueries in `from` and `where`Ryuta Kamizono2017-11-101-0/+3
| | | | | | | | | | | | Fixes #21577.
* | | Move Attribute and AttributeSet to ActiveModelLisa Ugray2017-11-091-2/+2
|/ / | | | | | | | | Use these to back the attributes API. Stop automatically including ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.