aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency.rb
Commit message (Collapse)AuthorAgeFilesLines
* Eager loading with polymorphic associations should behave consistentlyRyuta Kamizono2018-03-041-4/+2
| | | | | | | | | | This reverts ignoring polymorphic error introduced at 02da8ae. What the ignoring want to solve was caused by force eager loading regardless of whether it is necessary, but it has been fixed by #29043. The ignoring is now only causing a mismatch of `exists?` behavior with `to_a`, `count`, etc. It should behave consistently.
* Remove staled comment for `JoinDependency#initialize`Ryuta Kamizono2018-03-021-21/+0
| | | | | | | | | | | This comment was added at 070dda2. That arguments has already been changed since those are internal nodoc classes, but the comment does not reflect the current state. I decided to remove the staled comment since it is not useful for understanding what the class does. [ci skip]
* Joined tables in association scope doesn't use the same aliases with the ↵Ryuta Kamizono2017-10-091-3/+4
| | | | | | | | | parent relation's aliases Building association scope in join dependency should respect the parent relation's aliases to avoid using the same alias name more than once. Fixes #30681.
* Decouple building `AliasTracker` from `JoinDependency`Ryuta Kamizono2017-10-081-2/+2
| | | | | This is preparation to respect parent relation's alias tracking for fixing #30681.
* Ensure `AliasTracker` respects a custom table nameRyuta Kamizono2017-09-301-1/+1
|
* Scope in associations should treat nil as `all`Ryuta Kamizono2017-09-041-1/+2
| | | | | | | | Defined scope treats nil as `all`, but scope in associations isn't so. If the result of the scope is nil, most features on associations will be broken. It should treat nil as `all` like defined scope. Fixes #20823.
* Should work inverse association when eager loadingRyuta Kamizono2017-08-251-3/+3
| | | | | | | This regression was caused by caa178c1. The block for `set_inverse_instance` should also be passed to join dependency. Fixes #30402.
* Remove useless `JoinInformation`Ryuta Kamizono2017-07-251-2/+2
| | | | | Since 213796f removed `binds`, `JoinInformation` only contain `joins`. So it is enough to return `joins` simply.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Fix `JoinDependency` with using a custom tableRyuta Kamizono2017-07-181-2/+2
| | | | | | | | | | | | | | | Without this fix, `JoinDependency` doesn't use a custom table alias: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_with_joins_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_with_joins_affects_the_wheres --seed 14531 E Error:RelationTest#test_using_a_custom_table_with_joins_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.author_id: SELECT "omg_posts".* FROM "posts" "omg_posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" WHERE "omg_posts"."title" = ? LIMIT ? ```
* Remove useless `aliased_table_name` in `JoinDependency`Ryuta Kamizono2017-07-151-5/+1
| | | | If `table.table_alias` is not nil, it is enough to use `table` simply.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-2/+1
|\ \ | |/ |/| | | Make ActiveSupport frozen-string-literal friendly.
| * Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-2/+1
| |
* | The AliasTracker#aliased_table_for needs the type caster for the joined ↵Ray Zane2017-06-251-2/+3
| | | | | | | | association, not the join root
* | Keep INNER JOIN when merging relationsMaxime Lapointe2017-06-201-3/+3
|/ | | | | | | | | | | | | | | | | Doing `Author.joins(:posts).merge(Post.joins(:comments))` does this `SELECT ... INNER JOIN posts ON... LEFT OUTER JOIN comments ON...` instead of doing `SELECT ... INNER JOIN posts ON... INNER JOIN comments ON...`. This behavior is unexpected and makes little sense as, basically, doing `Post.joins(:comments)` means I want posts that have comments. Turning it to a LEFT JOIN means I want posts and join the comments data, if any. We can see this problem directly in the existing tests. The test_relation_merging_with_merged_joins_as_symbols only does joins from posts to comments to ratings while the ratings fixture isn't loaded, but the count is non-zero.
* Refactor making join constraintsRyuta Kamizono2017-05-231-23/+6
| | | | | The only difference between `make_inner_joins` and `make_left_outer_joins` is the `join_type`.
* Remove `node` parameter to `join_constraints`Aaron Patterson2017-03-031-1/+1
| | | | | I don't think we actually need this parameter anymore. Nobody seems to be using it.
* Fix `scopes` implementation on `PolymorphicReflection`Aaron Patterson2017-01-301-1/+1
| | | | `PolymorphicReflection` needs to be custom for handling scope lambdas
* class Foo < Struct.new(:x) creates an extra unneeded anonymous classAkira Matsuda2017-01-131-1/+1
| | | | because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-9/+9
|
* fixes remaining RuboCop issues [Vipul A M, Xavier Noria]Xavier Noria2016-09-011-2/+2
|
* Ensure that inverse associations are set before running callbacksSean Griffin2016-08-311-3/+5
| | | | | | | | | | | | | | | | | If a parent association was accessed in an `after_find` or `after_initialize` callback, it would always end up loading the association, and then immediately overwriting the association we just loaded. If this occurred in a way that the parent's `current_scope` was set to eager load the child, this would result in an infinite loop and eventually overflow the stack. For records that are created with `.new`, we have a mechanism to perform an action before the callbacks are run. I've introduced the same code path for records created with `instantiate`, and updated all code which sets inverse instances on newly loaded associations to use this block instead. Fixes #26320.
* Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-1/+5
|\ | | | | | | Preserve readonly flag only for readonly association
| * Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-1/+3
| | | | | | | | Fixes #24093
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-105/+105
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-3/+3
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Exists shouldn't error when used with `includes`Sean Griffin2016-05-301-2/+4
| | | | | | | | | | | | | | | | Currently `exists?` does some hackery where it assumes that we can join onto anything that we passed to `eager_load` or `includes`, which doesn't work if we are joining onto a polymorphic association. Actually figuring out if we want to include something would require knowledge deep within the join dependency module, which is hard to pull up. The simplest solution is just to pass a flag down that says we're not actually going to try to eager load any of the data. It's not the solution I'd like, but that code really needs to be untangled before we can do much with it. This is another attempt at 6d5b1fd which should address the concerns that led to reverting it in 4ecabed.
* Improve clarity of error message for missing includes and eager_loadJames Wen2016-01-281-1/+1
| | | | relations
* docs, `ActiveRecord::JoinDependency` is not part of the public API.Yves Senn2015-11-071-1/+1
| | | | | | | [ci skip] While `JoinDependency` and `JoinDependency::Aliases` were nodoced, the inner `Table` class made them appear in the API.
* Merge pull request #12071 from Crunch09/outer_joinsSean Griffin2015-10-301-2/+15
|\ | | | | | | added ActiveRecord::Relation#outer_joins
| * added ActiveRecord::Relation#left_outer_joinsFlorian Thomas2015-05-191-2/+15
| | | | | | | | | | | | Example: User.left_outer_joins(:posts) => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"
* | Merge pull request #18383 from ↵Rafael Mendonça França2015-10-271-1/+2
|\ \ | | | | | | | | | | | | | | | scambra/habtm-with-where-includes-16032-for-master Includes HABTM returns correct size now
| * | Includes HABTM returns correct size now. It's caused by the join dependencySergio Cambra2015-01-071-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
* | | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-041-6/+5
| |/ |/| | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems
* | Merge pull request #16989 from Empact/reload-cache-clearRafael Mendonça França2015-02-201-6/+4
|\ \ | | | | | | | | | Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
| * | Isolate access to @associations_cache and @aggregations cache to the ↵Ben Woosley2014-09-281-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | Associations and Aggregations modules, respectively. This includes replacing the `association_cache` accessor with a more limited `association_cached?` accessor and making `clear_association_cache` and `clear_aggregation_cache` private.
* | | Fix n+1 query problem when eager loading nil associations (fixes #18312)Sammy Larbi2015-01-031-1/+6
| |/ |/|
* | Move `#type_caster` to alias tracker initializeeileencodes2015-01-021-6/+2
| | | | | | | | | | This moves the `#type_caster` from the `aliased_table_for` and into the initialize of the `alias_tracker`.
* | Initialze `#alias_tracker` with base table nameeileencodes2015-01-021-2/+1
| | | | | | | | | | | | | | Instead of initializing an empty connection use the base table name instead. Split up and refactor `#create` to be 2 methods `#create` and `#create_with_joins`. Removes the need to update the count by 1 on initialzing a JoinDependency.
* | Pass a type caster when aliasing tables for joinsSean Griffin2014-12-291-2/+6
| |
* | `eager_load` preserves readonly flag for associationsTakashi Kokubun2014-12-301-0/+1
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| |
* | Combine aliased_table_for and aliased_name_foreileencodes2014-11-241-1/+1
| | | | | | | | | | | | | | | | | | This refactoring reduces the number of conditionals needed to build `aliased_table_for` and removes `aliased_name_for` because it's no longer necessary. `aliased_name_for` was also used in `JoinDependency#initialize` so that was replaced with `aliased_table_for` as well.
* | measure record instantiation time in AS::NotificationsAaron Patterson2014-10-131-3/+12
|/ | | | | emit an event when we instantiate AR objects so we can see how many records were instantiated and how long it took
* Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-3/+1
| | | | | | | | | | | | | Attempting to reduce the number of places that care about the details of how type casting occurs. We remove the type casting of the primary key in `JoinDependecy`, rather than encapsulating it. It was originally added for consistency with https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211, but that conditional was later removed in https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734. What is important is that the same row twice will have the same value for the primary key, which it will.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* fix polymorphic? method and reuse iteileencodes2014-06-021-1/+1
| | | | | | Fix polymorphic to check for `options[:polymorphic]` instead of `options.key? :polymorphic` and then reuse the method `polymorphic?` method instead of constantly checking the same `options[:polymorphic]`.