aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_scope.rb
Commit message (Collapse)AuthorAgeFilesLines
* Ensure `AliasTracker` respects a custom table nameRyuta Kamizono2017-09-301-1/+1
|
* Remove unnecessary `join_type` in `AssociationScope`Ryuta Kamizono2017-09-081-5/+1
| | | | | | This method was moved from `JoinHelper` in 0fddc3c1, but it is only used for `table.create_join` in the internal and `Nodes::InnerJoin` is default join klass. So it is not needed to pass it explicitly.
* Don't pass `table` to `last_chain_scope` and `next_chain_scope`Ryuta Kamizono2017-09-071-17/+15
| | | | | | Because `table` is part of `reflection`, don't need to pass it explicitly. And also, naming `alias_name` to `table` is a little confusing. `aliased_table` is preferable than `alias_name`.
* `has_many :through` with unscope should affect to through scopeRyuta Kamizono2017-09-071-21/+14
| | | | | | | | | The order of scope evaluation should be from through scope to the association's own scope. Otherwise the association's scope cannot affect to through scope. Fixes #13677. Closes #28449.
* Don't pass unneeded `reflection` to `add_constraints`Ryuta Kamizono2017-09-051-3/+3
| | | | Because `refl.scope` is the same meaning with `chain_head.scope`.
* 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.
* Specify `table.name` only when `scope.table` and `table` are different (#29058)Ryuta Kamizono2017-08-111-4/+12
| | | Fixes #29045.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* 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.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Don't passing `klass.connection` to `AssociationScope`Ryuta Kamizono2017-06-291-4/+4
| | | | | Passing `klass.connection` is redundant because `AssociationScope` is passed an association itself and an association has `klass`.
* Merge pull request #29557 from kamipo/extract_build_scope_and_predicate_builderRafael França2017-06-261-4/+3
|\ | | | | Extract `build_scope` and `predicate_builder` in `Reflection`
| * Extract `build_scope` and `predicate_builder` in `Reflection`Ryuta Kamizono2017-06-241-4/+3
| |
* | The AliasTracker#aliased_table_for needs the type caster for the joined ↵Ray Zane2017-06-251-2/+6
|/ | | | association, not the join root
* Fix association with extension issuesRyuta Kamizono2017-05-281-1/+1
| | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* remove unused parametersAaron Patterson2017-03-031-6/+6
|
* `join_keys` no longer needs a class passed to itAaron Patterson2017-03-031-2/+2
| | | | | | 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.
* Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-011-5/+6
| | | | Fixes #27666.
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-79/+79
|
* Replacement cycle for readabilityMolchanov Andrey2016-05-101-2/+1
|
* Allow symbols using "dot notation" to be passed to whereSean Griffin2016-04-121-2/+2
| | | | | | | | | | | | | | | | | In 04ac5655be91f49cd4dfe2838df96213502fb274 I assumed that we would never want to pass the "table_name.column_name" form to where with a symbol. However, in Ruby 2.2 and later, you can quote symbols using the new hash syntax, so it's a semi-reasonable thing to do if we want to support the dot notation (which I'd rather deprecate, but that would be too painful of a migration). Instead we've changed the definition of "this is a table name with a dot" to when the value associated is a hash. It would make very little sense to write `where("table_name.column_name": { foo: :bar })` in any scenario (other than equality for a JSON column which we don't support through `where` in this way). Close #24514.
* Ensure associations still work when the table name contains a dotSean Griffin2016-03-311-2/+2
| | | | | | | | | | | | | | | This issue occured because associations now call `where` directly, and a dot in the key name for `where` means nested tables. For this fix, we now pass the table name as a symbol, and do not attempt to expand symbols containing a dot. This is a temporary fix. I do not think we should support table names containing a dot, as it has a special meaning in most backends, as well as most APIs that involve table names. This commit does not include a test, as I am going to deprecate table names containing dots in the following commit. Fixes #24367
* Changed the order of Association constraints from where->order->unscope to ↵kal2015-10-201-1/+1
| | | | unscope->where->order
* Correct through associations using scopesSean Griffin2015-06-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | The changes introduced to through associations in c80487eb were quite interesting. Changing `relation.merge!(scope)` to `relation = relation.merge(scope)` should in theory never cause any changes in behavior. The subtle breakage led to a surprising conclusion. The old code wasn't doing anything! Since `merge!` calls `instance_exec` when given a proc, and most scopes will look something like `has_many :foos, -> { where(foo: :bar) }`, if we're not capturing the return value, it's a no-op. However, removing the `merge` causes `unscope` to break. While we're merging in the rest of the chain elsewhere, we were never merging in `unscope` values, causing a breakage on associations where a default scope was being unscoped in an association scope (yuk!). This is subtly related to #20722, since it appears we were previously relying on this mutability. Fixes #20721. Fixes #20727.
* Go through normal `where` logic in `AssociationScope`Sean Griffin2015-01-261-51/+31
| | | | | | | | | | | | This removes the need to duplicate much of the logic in `WhereClause` and `PredicateBuilder`, simplifies the code, removes the need for the connection adapter to be continuously passed around, and removes one place that cares about the internal representation of `bind_values` Part of the larger refactoring to change how binds are represented internally [Sean Griffin & anthonynavarre]
* Remove all references to `where_values` in association codeSean Griffin2015-01-251-2/+1
|
* Remove references to `:bind` in `except`Sean Griffin2015-01-251-1/+1
| | | | Bind values are no longer a thing, so this is unnecessary.
* Cleanup methods, missing spacing and missing nodocseileencodes2015-01-021-19/+20
| | | | | | | | | | Add missing nodoc's Change `assoc_klass` argument name to `association_klass` Change `prev_reflection` argument name to `previous_reflection` Change `prev` to `previous_reflection` in `#get_chain` Switch use of `refl` and `reflection` in `#get_chain` so main parameter is not abbreviated. Add missing space in `#add_constraints`
* Move `#type_caster` to alias tracker initializeeileencodes2015-01-021-1/+1
| | | | | This moves the `#type_caster` from the `aliased_table_for` and into the initialize of the `alias_tracker`.
* Add `#all_includes` method to reflectionseileencodes2015-01-021-1/+3
| | | | | `yield` instead of relying on checking if the reflection is equal to the `chain_head`.
* Initialze `#alias_tracker` with base table nameeileencodes2015-01-021-1/+0
| | | | | | | 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.
* Move `alias_candiate` into `AbstractReflection`eileencodes2015-01-021-9/+7
| | | | | | This moves `alias_candidate` out of the `ReflectionProxy` and into the `AbstractReflection` so it is shared by all reflections. Change `alias_name` to a method and and remove assignment in `#get_chain`.
* Pass `connection` rather than `alias_tracker`eileencodes2015-01-021-4/+4
| | | | | | | | | After the refactorings we're only using the connection and not the alias tracker anymore. This builds on commit 18019. Reuse the already available `@connection` to reduce the surface area of the alias tracker's API. We can then remove the `attr_reader` because the connection is already available.
* Assign the `#alias_name` to each reflectioneileencodes2015-01-021-11/+12
| | | | This makes the `#alias_name` more functional.
* Clean up / refactor new reflection classeseileencodes2015-01-021-50/+1
| | | | | | Move `RuntimeReflection` and `PolymorphicReflect` into Reflection. This allows the methods to inherit from `ThroughReflection` and DRY up the methods by removing duplicates.
* Refactor `#get_chain` iteration to a linked listeileencodes2015-01-021-14/+21
| | | | | | The linked list lets us use a loop in `#add_constraints` and completely remove the need for indexing the iteration becasue we have access to the next item in the chain.
* Refactor `#get_chain` to remove need for `#construct_tables`eileencodes2015-01-021-14/+11
| | | | | | By concatnating the `ReflectionProxy` with the `chain` we remove the need for `#construct_tables` because the `chain` is now in the correct order (order of the chain DOES matter).
* Move `#alias_name` to `ReflectionProxy` classeileencodes2015-01-021-10/+23
| | | | | Putting the `#alias_name` into ReflectionProxy means we don't have to cache the `#alias_name` globally anymore - it's not cached per query.
* Clean up assignments in `#add_constraints`eileencodes2015-01-021-8/+3
| | | | | | `is_first_chain`, `items` and `klass` are no longer beneficial and can be called directly instead of via their assignments - because they are each only used once.
* Refactor construct_tables methodeileencodes2015-01-021-36/+10
| | | | | Move method structure into reflection classes for accessibly on each reflection rather than by traversing the chain.
* Add RuntimeReflection for recursive access to chaineileencodes2015-01-021-3/+54
| | | | | | | The `RuntimeReflection` class allows the reflection to be accessed at runtime - then we always know which reflection we are accessing in the chain. The `#get_chain` method then allows us to recursively access the chain through the `RuntimeReflection`.
* Add PolymorphicReflection and constraints methodeileencodes2015-01-021-3/+4
| | | | | | `#constraints` builds a flattened version of `scope_chain` to allow it to be accessible without requiring an index when iterating over the `scope_chain`
* Pass a type caster when aliasing tables for joinsSean Griffin2014-12-291-1/+2
|
* Pass connection rather than alias_trackereileencodes2014-12-131-16/+17
| | | | | | | | | Because we're only using the `connection` so passing the entire tracker isn't unnecessary. Eventually only the `connection` will be passed to `add_constraints` with later refactoring but curretly that's not possible because of `construct_tables` method.
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-2/+1
| | | | Oh hey, we got to remove some code because of that!
* Merge pull request #16801 from ↵Rafael Mendonça França2014-09-041-5/+1
|\ | | | | | | | | eileencodes/refactor-scope_chain-on-through-refelction-to-eliminate-branch-in-eval_scope Always add lambda to scope chain to eliminate branch in eval_scope
| * Always add lambda to scope chain to eliminate branch in eval_scopeeileencodes2014-09-041-5/+1
| | | | | | | | | | | | We convert all other scopes to lambda's so it makes sense that we should always returns a lambda on a ThroughReflection as well. This eliminates the need to check if the scope is a Relation.
* | Follup to PR #16762eileencodes2014-09-041-4/+4
|/ | | | | | | | Remove chain from parameters, it's no longer needed since chain and i are being passed via next_reflection Change name of `reflection` to `owner_reflection` because of shadow variable warning. The last reflection will always be the owner.
* get rid of shadowing warning when running tests AR and railtie tests.Yves Senn2014-09-041-2/+2
| | | | | | | | Warning looked like this: ``` /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:142: warning: shadowing outer local variable - reflection ```