aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency
Commit message (Collapse)AuthorAgeFilesLines
* Fix eager loading associations with string joins not to raise NoMethodErrorRyuta Kamizono2019-05-151-2/+11
| | | | Fixes #34456.
* Fix eager loading polymorphic association with mixed table conditionsRyuta Kamizono2019-02-181-6/+11
| | | | | | This fixes a bug that the `foreign_key` and the `foreign_type` are separated as different table conditions if a polymorphic association has a scope that joins another tables.
* Avoid unneeded expanded column aliases array cachingRyuta Kamizono2018-07-101-2/+2
|
* Don't extract `readonly_value` each timeRyuta Kamizono2018-07-031-0/+6
|
* Ensure to calculate column aliases after all table aliases are constructedRyuta Kamizono2018-06-192-18/+19
| | | | | | | | | | | | | | | | | 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.
* Use private attr_readerRyuta Kamizono2018-02-231-1/+1
| | | | | Since #32028, Rails 6 requires Ruby 2.3+. No longer needed workaround for Ruby 2.2 "private attribute?" warning.
* [Active Record] require => require_relativeAkira Matsuda2017-10-212-2/+2
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Joined tables in association scope doesn't use the same aliases with the ↵Ryuta Kamizono2017-10-091-6/+11
| | | | | | | | | 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.
* Remove useless `JoinInformation`Ryuta Kamizono2017-07-251-3/+1
| | | | | Since 213796f removed `binds`, `JoinInformation` only contain `joins`. So it is enough to return `joins` simply.
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-193-0/+6
|
* Fix `JoinDependency` with using a custom tableRyuta Kamizono2017-07-181-4/+7
| | | | | | | | | | | | | | | 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-153-13/+0
| | | | If `table.table_alias` is not nil, it is enough to use `table` simply.
* Fix eager loading association with scope including joinsRyuta Kamizono2017-07-041-4/+10
| | | | Fixes #28324.
* [Active Record] require => require_relativeAkira Matsuda2017-07-012-2/+2
|
* Move building constraint to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-39/+3
|
* Move constructing polymorphic type to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-10/+2
|
* Move constructing join scope to `Reflection`Ryuta Kamizono2017-06-261-9/+1
|
* Extract `build_scope` and `predicate_builder` in `Reflection`Ryuta Kamizono2017-06-241-1/+1
|
* Remove unused `JoinPart#name`Ryuta Kamizono2017-05-221-4/+0
|
* `join_keys` no longer needs a class passed to itAaron Patterson2017-03-031-1/+1
| | | | | | Reflections only use their own information to create a `join_keys` object. This means that we can call `join_keys` on a reflection object and have it be context-free.
* ask reflection for klass join reflectionAaron Patterson2017-03-031-13/+1
|
* Move join scopes on to the reflection objectAaron Patterson2017-03-031-8/+1
| | | | | | | Scopes can only ever be *not* reflection objects when they are passed in to the Reflection constructor. Given this fact, we can eliminate is_a checks and an intermediate array object by just asking the reflection object for join scopes.
* Remove `node` parameter to `join_constraints`Aaron Patterson2017-03-031-2/+2
| | | | | 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-6/+2
| | | | `PolymorphicReflection` needs to be custom for handling scope lambdas
* Ensure that inverse associations are set before running callbacksSean Griffin2016-08-311-2/+2
| | | | | | | | | | | | | | | | | 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.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-062-2/+2
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Remove circular join references in join_dependencyTakashi Kokubun2016-07-281-1/+3
| | | | Fixes #25653.
* Merge pull request #18109 from k0kubun/unscoped-joinsSean Griffin2016-02-111-6/+12
|\ | | | | | | | | | | Allow `joins` to be unscoped Fixes #13775
| * Allow `joins` to be unscopedTakashi Kokubun2016-01-311-6/+12
| |
* | Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-1/+1
|/ | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* `substitute_at` is no longer usedRyuta Kamizono2016-01-141-2/+1
| | | | Arel handles substitution for bind parameters by now.
* Remove Relation#bind_paramsSean Griffin2015-01-271-1/+1
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Use an `Attribute` object to represent a bind valueSean Griffin2015-01-271-4/+4
| | | | | | | | | | | The column is primarily used for type casting, which we're trying to separate from the idea of a column. Since what we really need is the combination of a name, type, and value, let's use the object that we already have to represent that concept, rather than this tuple. No consumers of the bind values have been changed, only the producers (outside of tests which care too much about internals). This is *finally* possible since the bind values are now produced from a reasonable number of lcoations.
* Remove `klass` and `arel_table` as a dependency of `PredicateBuilder`Sean Griffin2014-12-261-1/+1
| | | | | | | | | | | | | | | This class cares far too much about the internals of other parts of Active Record. This is an attempt to break out a meaningful object which represents the needs of the predicate builder. I'm not fully satisfied with the name, but the general concept is an object which represents a table, the associations to/from that table, and the types associated with it. Many of these exist at the `ActiveRecord::Base` class level, not as properties of the table itself, hence the need for another object. Currently it provides these by holding a reference to the class, but that will likely change in the future. This allows the predicate builder to remain wholy concerned with building predicates. /cc @mrgilman
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-2/+9
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-1/+1
| | | | Oh hey, we got to remove some code because of that!
* Remove defunct ivarsBen Woosley2014-09-281-1/+0
| | | | @column_names_with_alias, @dynamic_methods_hash, @time_zone_column_names, and @cached_time_zone
* Fixed regression with referencing polymorphic assoc in eager-loadGodfrey Chan2014-09-051-1/+1
| | | | | | | | | | | | This is cased by 03118bc + 9b5d603. The first commit referenced the undefined local variable `column` when it should be using `reflection.type` as the lookup key. The second commit changed `build_arel` to not modify the `bind_values` in- place so we need to combine the arel's `bind_values` with the relation's when building the SQL. Fixes #16591 Related #15821 / #15892 / 7aeca50
* Merge pull request #16378 from ↵Rafael Mendonça França2014-08-021-1/+1
|\ | | | | | | | | JackDanger/doc-fix-in-join-association-build_constraint [doc] updating documented parameter for build_constraint
| * updating documented parameter for build_constraintJack Danger Canty2014-08-021-1/+1
| | | | | | | | | | Updates documentation in line with changes made in 743b67508e2027e1d086142ccbec47a19fc943f6
* | Refactor join_keys to remove complex conditionalseileencodes2014-07-311-8/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | Pushing conditionals down to through reflection Only the through association needs the part of this conditional that deals with belongs to and polymorphic? so that can be pushed down into the ThroughReflection reducing the conditionals. Remove conditional because we can delegate join keys to source reflection Remove need for source_macro checking By adding join_id_for to the other reflections we remove the need to cehck against the source_macro and can reduce the conditioanl from the original join_id_for(owner) Using polymorphism instead of testing the source_macro This case statement in join_association is almost exactly the same as the original join_keys code. Testing taht theory by creating a new join_dependency_keys(assoc_klass) method. Refactor join_keys further to be more concise Fixed format of "#:nodoc:" to "# :nodoc:" where I added them to this file.
* [ci skip] Fix documentation for @macro and reflection typeseileencodes2014-07-271-1/+1
| | | | | | | | Since `@macro` doesn't exist anymore and these reflections are no longer AssociationReflections but their own types of reflections based on macro I updated the documentation to match the changes I made in #16089 and #16198. An `AssociationReflection` that had a `@macro` of `:has_many` now is a `HasManyReflection`
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Pass a base relation to build_default_scope when joiningMatt Jones2014-02-211-1/+1
| | | | | | | | | | This allows the default scope to be built using the current table alias. Resolves #12770
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-2/+4
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (311 commits) Add a missing changelog entry for #13981 and #14035 Revert "Fixed plugin_generator test" implements new option :month_format_string for date select helpers [Closes #13618] add factory methods for empty alias trackers guarantee a list in the alias tracker so we can remove a conditional stop exposing table_joins make most parameters to the AliasTracker required make a singleton for AssociationScope pass the association and connection to the scope method pass the tracker down the stack and construct it in the scope method clean up add_constraints signature remove the reflection delegate remove klass delegator remove railties changes. fixes #14054 remove chain delegate remove scope_chain delegate Add verb to sanitization note fix path shown in mailer's templates updated Travis build status image url fix guide active_support_core_extensions. add Note to String#indent [ci skip] ... Conflicts: activerecord/lib/active_record/associations/join_dependency.rb activerecord/test/cases/associations/association_scope_test.rb
| * Dont use Enumarator on join_associationArthur Neves2014-02-131-2/+4
| |
* | expliticly make STI column a bind valueAaron Patterson2014-01-141-4/+9
| |
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-141-6/+4
|\| | | | | | | | | | | * master: directly create the ARel AST Updated comment to mention the enum mapping class method [ci skip]