aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Remove references to `:bind` in `except`Sean Griffin2015-01-251-1/+1
| | | | Bind values are no longer a thing, so this is unnecessary.
* Don't access the where values hash directly in through associationsSean Griffin2015-01-251-1/+1
| | | | See 4d7a62293e148604045a5f78a9d4312e79e90d13 for the reasoning
* Don't rely as much on the structure of the values hash in associationsSean Griffin2015-01-252-2/+2
| | | | | | | | | The structure of `values[:where]` is going to change, with an intermediate definition of `where_values` to aid the refactoring. Accessing `values[:where]` directly messes with that, signficantly. The array wrapping is no longer necessary, since `where_values` will always return an array.
* Don't rely on relation mutability when building through associationsSean Griffin2015-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | Specifically, the issue is relying on `where_unscoping` mutating the where values. It does not, however, mutate the bind values, which could cause an error under certain circumstances. This was not exposed by the tests, since the only place which would have been affected is unscoping a boolean, which doesn't go through prepared statements. I had a hard time getting better test coverage to demonstrate the issue. This in turn, caused `merge` to go through proper logic, and try to clear out the binds associated with the unscoped relation, which then exposed a source of `nil` for the columns, as binds weren't expanding `{ "posts.id" => 1 }` to `{ "posts" => { "id" => 1 } }`. This has been fixed. The bulk of `create_binds` needed to be moved to a separate method, since the dot notation should not be expanded recursively. I'm pretty sure this removes a subtle quirk that a ton of code in `Relation::Merger` is working around, and I suspect that code can be greatly simplified. However, unraveling that rats nest is no small task.
* Remove unneeded requiresRafael Mendonça França2015-01-041-2/+0
| | | | These requires were added only to change deprecation message
* Return a null column from `column_for_attribute` when no column exists.Rafael Mendonça França2015-01-041-2/+2
| | | | | | | | This reverts commit ae96f229f6501d8635811d6b22d75d43cdb880a4. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods.rb
* Remove deprecated automatic counter caches on `has_many :through`Rafael Mendonça França2015-01-041-14/+0
|
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-022-2/+2
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* 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-023-13/+10
| | | | | 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-023-11/+12
| | | | | | | 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-022-7/+7
| | | | | | | | | 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`
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-0/+11
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-0/+11
| |
* | Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-029-76/+48
| |
* | Share foreign_key_present? implementation in _has_ associationsbrainopia2014-12-313-8/+13
| |
* | Ensure `first!` and friends work on loaded associationsSean Griffin2014-12-291-0/+1
| | | | | | | | Fixes #18237
* | Pass a type caster when aliasing tables for joinsSean Griffin2014-12-293-6/+11
| |
* | `eager_load` preserves readonly flag for associationsTakashi Kokubun2014-12-301-0/+1
| |
* | Go through normal `where` logic when preloading associationsSean Griffin2014-12-261-1/+1
| | | | | | | | | | | | | | | | | | | | This will allow eager type casting to take place as needed. There doesn't seem to be any particular reason that the `in` statement was forced for single values, and the commit message where it was introduced gives no context. See https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
* | 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-263-4/+11
| | | | | | | | | | | | | | 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
* | - Changed `target` to `target_reflection` to avoid warning `possible ↵Vipul A M2014-12-251-2/+2
| | | | | | | | reference to past scope`
* | Remove unneeded special case to calculate size for has_many :throughBogdan Gusiev2014-12-231-15/+0
| | | | | | | | | | All cases are properly handled in CollectionAssociation for all subclasses of this association
* | Improve the performance of reading belongs_to associationsSean Griffin2014-12-221-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | `ActiveRecord::Base#[]` has overhead that was introduced in 4.2. The `foo["id"]` working with PKs other than ID isn't really a case that we want to support publicly, but deprecating was painful enough that we avoid it. `_read_attribute` was introduced as the faster alternative for use internally. By using that, we can save a lot of overhead. We also save some overhead by reading the attribute one fewer times in `stale_state`. Fixes #18151
* | 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.
* | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-082-2/+2
| | | | | | | | | | | | | | To be possible to use a custom column name to save/read the polymorphic associated type in a has_many or has_one polymorphic association, now users can use the option :foreign_type to inform in what column the associated object type will be saved.
* | Update Arel usage for rails/arel#98fc259Sean Griffin2014-11-291-1/+1
| | | | | | | | | | `where_sql` now requires that we pass it an engine. None of the manager classes take an engine in their constructor.
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-294-10/+8
| |
* | Adds preloaded_records method to NullPreloaderThorsten Ball2014-11-281-0/+1
| | | | | | | | | | | | | | | | This fixes a regression where preloading association throws an exception if one of the associations in the preloading hash doesn't exist for one record. Fixes #16070
* | Setting an association replaces records with the same id in memorySean Griffin2014-11-251-2/+18
| | | | | | | | | | | | | | | | | | | | | | The records weren't being replaced since equality in Active Record is defined in terms of `id` only. It is reasonable to expect that the references would be replaced in memory, even if no queries are actually executed. This change did not appear to affect any other parts of the code base. I chose not to execute callbacks since we're not actually modifying the association in a way that will be persisted. Fixes #17730
* | Combine aliased_table_for and aliased_name_foreileencodes2014-11-242-13/+4
| | | | | | | | | | | | | | | | | | 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.
* | Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-8/+2
| | | | | | | | on the joined assoiciation
* | Wrap code snippets in +, not backticks, in sdocclaudiob2014-11-201-2/+2
| | | | | | | | | | | | | | | | I grepped the source code for code snippets wrapped in backticks in the comments and replaced the backticks with plus signs so they are correctly displayed in the Rails documentation. [ci skip]
* | Merge pull request #17575 from shikshachauhan/make-habtm-consistentRafael Mendonça França2014-11-191-1/+1
|\ \ | | | | | | Allow class_name option in habtm to be consistent with other association...
| * | Allow habtm class_name option to be consistent with other associationsshiksha2014-11-131-1/+1
| | |
* | | Improve the performance of reading attributesSean Griffin2014-11-182-2/+2
| | | | | | | | | | | | | | | | | | | | | We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
* | | Remove the unused second argument to `substitute_at`Sean Griffin2014-11-172-3/+2
| | | | | | | | | | | | Oh hey, we got to remove some code because of that!
* | | Merge pull request #11694 from ↵Rafael Mendonça França2014-11-101-1/+7
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | | | | Empact/association-bind-values-not-updated-on-save Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id Conflicts: activerecord/CHANGELOG.md