aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-172-8/+2
|
* 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 formatting of `pick` [ci skip]yuuji.yaginuma2018-02-101-1/+1
| |
* | Add Relation#pick as short-hand for single-value plucks (#31941)David Heinemeier Hansson2018-02-091-0/+18
| | | | | | * Add Relation#pick as short-hand for single-value plucks
* | Avoid extra calls to to_sDaniel Colson2018-01-291-1/+1
| | | | | | | | | | | | | | With #31615 `type_for_attribute` accepts either a symbol as well as a string. `has_attribute?` and `attribute_alias` also accept either. Since these methods call `to_s` on the argument, we no longer need to do that at the call site.
* | Fix expanding an array of `composed_of` objects which have multiple mappingsRyuta Kamizono2018-01-292-1/+12
| | | | | | | | | | | | | | | | | | Follow up of #31724. If `composed_of` objects have multiple mappings, array predicate handler can not correctly handle the expanded condition. We need to handle it like polymorphic association objects.
* | Fix `count(:all)` with eager loading and having an order other than the ↵Ryuta Kamizono2018-01-251-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | driving table This is a regression caused by 6beb4de. In PostgreSQL, ORDER BY expressions must appear in SELECT list when using DISTINCT. When using `count(:all)` with eager loading, Active Record enforces DISTINCT to count the driving table records only. 6beb4de was caused the regression because `count(:all)` with DISTINCT path no longer removes ORDER BY. We need to ignore ORDER BY when DISTINCT is enforced, otherwise not always generated valid SQL for PostgreSQL. Fixes #31783.
* | Avoid passing unnecessary arguments to relationDaniel Colson2018-01-242-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* | Fix relation merger issue with `left_outer_joins`Mehmet Emin INAC2018-01-152-1/+27
| |
* | 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`.
* | | Don't pass garbage args to alias trackerRyuta Kamizono2018-01-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a complete fix to #30995. Originally alias tracker will only track table aliases on `Arel::Nodes::Join`, other args are ignored. Since c5ab6e5, parent aliases hash will be passed then it caused the regression #30995. It is enough to pass list of `Arel::Nodes::Join` simply, not need to pass garbage args which will be ignored.
* | | Use `apply_join_dependency` instead of meaningless named ↵Ryuta Kamizono2018-01-111-24/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `find_with_associations` `find_with_associations` is meaningless name in this point since it just contain `construct_join_dependency` and `apply_join_dependency`, does not contain finding anything. If `apply_join_dependency` returns `relation` and `join_dependency` then `find_with_associations` is no longer needed.
* | | Make `relation.exists?` more performant when using eager loadingRyuta Kamizono2018-01-111-3/+4
| | | | | | | | | | | | | | | | | | `relation.exists?` just wants to know if there is a result or not, does not need the exact records matched. Therefore, an intermediate SELECT query for eager loading is not necessary.
* | | resolve inconsistencies between first and to_a.first with limitBrian Christian2018-01-091-1/+5
| | |
* | | Make `find_nth_from_last` more performant when using reversible orderRyuta Kamizono2018-01-071-6/+5
| | | | | | | | | | | | | | | We can use `relation.last(index)[-index]` instead of loading all records when using reversible order because `last` will call `reverse_order`.
* | | Fix `last` with `offset` to behave consistently with loaded relationRyuta Kamizono2018-01-071-1/+1
| | | | | | | | | | | | | | | | | | Currently `last` with `offset` behaves incorrectly because `offset` can not be reversed like `limit`. Therefore, `offset` should also be handled like `limit`.
* | | Fix `pluck` with eager loading to respect `offset`Ryuta Kamizono2018-01-071-1/+1
| | |
* | | 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.
* | | Refactor delegating `join_primary_key` instead of `join_keys` and ↵Ryuta Kamizono2018-01-012-2/+2
| | | | | | | | | | | | | | | | | | | | | `association_primary_key` in `TableMetadata` Because `join_primary_key` is called by `join_keys` and it is to abstract calling `association_primary_key`.
* | | Place args normalization from `left_outer_joins` to `left_outer_joins!`Ryuta Kamizono2017-12-201-4/+2
| | | | | | | | | | | | Like other query bang methods.
* | | Fix `count(:all)` to correctly work `distinct` with custom SELECT listRyuta Kamizono2017-12-201-10/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `count(:all)` with `distinct` doesn't work correctly because SELECT list is always replaced to `*` or primary key in that case even if having custom SELECT list. And also, PostgreSQL has a limitation that ORDER BY expressions must appear in select list for SELECT DISTINCT. Therefore, we should not replace custom SELECT list when using `count(:all)` with `distinct`. Closes #31277.
* | | 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-132-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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
* | | Fix `scope_for_create` to do not lose polymorphic associationsRyuta Kamizono2017-12-081-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This regression was caused at 213796fb due to polymorphic predicates are combined by `Arel::Nodes::And`. But I'd like to keep that combined because it would help inverting polymorphic predicates correctly (e9ba12f7), and we can collect equality nodes regardless of combined by `Arel::Nodes::And` (`a AND (b AND c) AND d` == `a AND b AND c AND d`). This change fixes the regression to collect equality nodes in `Arel::Nodes::And` as well. Fixes #31338.
* | | Update docs `ActiveRecord::FinderMethods#find`suginoy2017-11-281-3/+4
| | | | | | | | | | | | ref https://github.com/rails/rails/pull/22653
* | | Provide arguments to RecordNotFoundNikita Misharin2017-11-251-5/+9
| | |
* | | Update `exists?` documentationNikolai B2017-11-141-1/+2
| | | | | | | | | | | | Make it clear that `exists?` can be chained onto a relation
* | | Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-142-1/+14
|\ \ \ | | | | | | | | | | | | 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-092-28/+5
| | | |
| * | | allow table name and direction in string order argBen Toews2017-11-092-25/+32
| | | |
| * | | 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-092-53/+21
| | | |
| * | | add config to check arguments to unsafe AR methodsBen Toews2017-11-092-14/+77
| | | |
* | | | 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.
* | | | Relation merging should keep joining orderRyuta Kamizono2017-11-111-10/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | `joins_values.partition` will break joins values order. It should be kept as user intended order. Fixes #15488.
* | | | Consolidate duplicated `to_ary`/`to_a` definitions in `Relation` and ↵Ryuta Kamizono2017-11-101-1/+1
| | | | | | | | | | | | | | | | `CollectionProxy`
* | | | Ensure `apply_join_dependency` for subqueries in `from` and `where`Ryuta Kamizono2017-11-102-0/+7
| | | | | | | | | | | | | | | | Fixes #21577.
* | | | Move Attribute and AttributeSet to ActiveModelLisa Ugray2017-11-092-4/+4
| |/ / |/| | | | | | | | | | | Use these to back the attributes API. Stop automatically including ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.
* | | Ensure `apply_join_dependency` for `collection_cache_key` if eager-loading ↵Ryuta Kamizono2017-11-062-3/+3
|/ / | | | | | | | | | | is needed Fixes #30315.
* | Fix duplicate aliases when using both INNER/LEFT JOINsRyuta Kamizono2017-10-231-3/+4
| | | | | | | | | | | | | | | | It should be shared the count of alias tracking in both INNER/LEFT JOINs to avoid duplicate aliases. Fixes #30504. Closes #30410.