aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Don't delegate Reflection#chain to ThroughAssociationeileencodes2014-08-041-2/+2
| | | | | | We shouldn't be delegating chain to ThroughAssociation since the only place that needs to call it is `target_scope`. Instead we can call `reflecion.chain`.
* 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
* | Use available method rather than macro name checkingCarlos Antonio da Silva2014-07-311-1/+1
| |
* | 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.
* | Redefine macro checks for reflectionseileencodes2014-07-301-1/+1
|/ | | | | | | | | | | | | | Now that we define the macro on the reflection type we no longer need to check `macro == :what` on each type for `belongs_to?` or `has_one?` etc. These now default to false unless it's defined in the reflection class. Reuse existing belongs_to? method to check macros We don't need to do `:belongs_to == macro` anymore becasue we have a `belongs_to?` method. I didn't find this being used anywhere for `has_one?` or `collection?` since they were already fixed.
* remove blank lines in the start of the ActiveRecord filesPonomarev Nikolay2014-07-292-2/+0
|
* [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`
* Remove unused 1:1 association :remote optionChris Griego2014-07-161-1/+1
| | | This option is unused, left over from pre-1.0 Rails to internally distinguish the location of the foreign key.
* Merge pull request #15266 from dv/use_counter_cache_for_empty_callGodfrey Chan2014-07-151-0/+8
|\ | | | | If a counter_cache exists, use it for #empty?
| * If a counter_cache exists, use it for #empty?David Verhasselt2014-06-101-0/+8
| |
* | Add a `required` option to singular associationsSean Griffin2014-07-042-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In addition to defining the association, a `required` association will also have its presence validated. Before: ```ruby belongs_to :account validates_presence_of :account ``` After: ```ruby belongs_to :account, required: true ``` This helps to draw a distinction between types of validations, since validations on associations are generally for data integrity purposes, and aren't usually set through form inputs.
* | Merge pull request #12450 from iantropov/masterRafael Mendonça França2014-06-273-5/+16
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | Fix bug, when ':dependent => :destroy' violates foreign key constraints Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/association.rb activerecord/lib/active_record/associations/builder/has_one.rb
| * | Fix bug, when ':dependent => :destroy' option violates foreign key ↵Ivan Antropov2013-10-263-9/+18
| | | | | | | | | | | | constraints, issue #12380
* | | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-262-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | | Merge pull request #15847 from sgrif/sg-encapsulate-result-typesRafael Mendonça França2014-06-261-3/+1
|\ \ \ | | | | | | | | Encapsulate knowledge of type objects on `ActiveRecord::Result`
| * | | 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.
* | | | `preload` preserves readonly flag on associations. #15853Yves Senn2014-06-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | This is a partial fix for #15853. It only works when a `preload` is issued and not an `eager_load`. I've added a skipped failing test-case to keep in mind that we need to deal with `eager_load`.
* | | | Add a deprecation cycle for `NullColumn` from `column_for_attribute`Sean Griffin2014-06-231-2/+2
|/ / / | | | | | | | | | | | | | | | This is public API, and `simple_form` depends on the `nil` return value. We need to go through a deprecation cycle to return a null object. If people want hash access, they can access the hash.
* | | Merge pull request #15747 from sgrif/sg-trolololol-this-is-so-brokenRafael Mendonça França2014-06-192-1/+26
|\ \ \ | | | | | | | | Always update counter caches in memory when adding records
| * | | Always update counter caches in memory when adding recordsSean Griffin2014-06-162-1/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before, calling `size` would only work if it skipped the cache, and would return a different result from the cache, but only if: - The association was previously loaded - Or you called size previously - But only if the size was 0 when you called it This ensures that the counter is appropriately updated in memory.
* | | | Merge pull request #15803 from sgrif/sg-column-in-associationsRafael Mendonça França2014-06-191-2/+2
|\ \ \ \ | | | | | | | | | | Don't rely on the column for type casting reflections
| * | | | Don't rely on the column for type casting reflectionsSean Griffin2014-06-181-2/+2
| |/ / /
* | | | Merge pull request #15772 from nbudin/sti_through_bugRafael Mendonça França2014-06-191-1/+3
|\ \ \ \ | | | | | | | | | | | | | | | Don't include inheritance column in the through_scope_attributes
| * | | | Don't include inheritance column in the through_scope_attributesNat Budin2014-06-171-1/+1
| |/ / /
* / / / Fix has_and_belongs_to_many in a namespaced model pointing to a non ↵Rafael Mendonça França2014-06-191-8/+5
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | namespaced model Now the following case will work fine class Tag < ActiveRecord::Base end class Publisher::Article < ActiveRecord::Base has_and_belongs_to_many :tags end Fixes #15761
* | | Merge pull request #15701 from zzak/issue_15496Rafael Mendonça França2014-06-131-1/+5
|\ \ \ | | | | | | | | Open extension point for defining options in build_through_record
| * | | Open extension point for defining options in build_through_recordZachary Scott2014-06-131-1/+5
| | | | | | | | | | | | | | | | This fixes #15496
* | | | Through associations should set both parent ids on join modelsSean Griffin2014-06-132-7/+15
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
* | / begin refactoring add_constraints by moving join keyseileencodes2014-06-101-12/+3
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | add_constraints is complicated and difficult to read. This is the beginning of a long process of refactoring this code. First step: moved the join keys out of AssociationScope and into reflection. We then don't need to call `reflection` because now reflection is `self`. `foreign_key` must be named something else because reflection already has a `foreign_key` method and when passed into `JoinKeys` it was getting the wrong assignment. `reflection_foreign_key` seemed to be an appropriate name. I also named `key` `reflection_key` to match `reflection_foreign_key`.
* | reuse available collection? check instead of macroeileencodes2014-06-092-4/+4
| | | | | | | | | | | | | | Reflection has an available method that is used to check if the reflection is a collection. Any :has_many macro is considered a collection and `collection?` should be used instead of `macro == :has_many`.
* | add has_one? method and reuse instead of checking macroeileencodes2014-06-093-3/+3
| | | | | | | | | | | | Instead of checking for `macro == :has_one` throughout the codebase we can create a `has_one?` method to match the `belongs_to?`, `polymorphic?` and other methods.
* | Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-092-2/+2
| | | | | | | | | | | | | | | | 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.
* | Do not try to set the foreign_key again on has_many throughRafael Mendonça França2014-06-091-1/+1
| | | | | | | | | | | | | | Integration tests are inside protected_attributes test suite. Fixes #15496 Fixes rails/protected_attributes#35
* | Remove a long gone :order option from has_one's valid_options.thedarkone2014-06-091-1/+1
| |
* | Use null column for association key typesSean Griffin2014-06-041-4/+2
| |
* | Merge pull request #15482 from laurocaetano/fix-regression-for-eager-loadCarlos Antonio da Silva2014-06-041-2/+4
|\ \ | | | | | | | | | | | | | | | | | | Fix regression on eager loading association based on SQL query rather than existing column. Conflicts: activerecord/CHANGELOG.md
| * | Fix regression on eager loading association based on SQL query ratherLauro Caetano2014-06-031-2/+4
| | | | | | | | | | | | | | | | | | than existing column. Fixes #15480.
* | | reuse available belongs_to? methodeileencodes2014-06-032-4/+3
|/ / | | | | | | | | | | | | | | | | | | Reflection has a `belongs_to?` method. Instead of checking for `macro == :belongs_to` throughout the source reuse existing method. I also bumped `foreign_key_present?` method onto on line because the `belongs_to?` makes it shorter than other longer lines in the same class.
* | fix polymorphic? method and reuse iteileencodes2014-06-022-2/+2
| | | | | | | | | | | | 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]`.
* | Merge pull request #14834 from al2o3cr/issue14155Aaron Patterson2014-05-271-1/+11
|\ \ | | | | | | Correctly alias table names when joining more than once
| * | WIP: pass existing joins to construct_join_dependencyMatt Jones2014-05-161-1/+11
| | |
* | | Merge pull request #15301 from zzak/issue_15212Rafael Mendonça França2014-05-261-0/+1
|\ \ \ | | | | | | | | | | | | Skip if the association was already loaded.
| * | | Skip if the association was already loaded.Zachary Scott2014-05-241-0/+1
| | | |
* | | | Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-244-5/+6
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb
* | | Merge pull request #14855 from laurocaetano/fix_polymorphic_with_string_keyYves Senn2014-05-211-4/+25
|\ \ \ | | | | | | | | | | | | Fix polymorphic eager load with foreign_key as String.
| * | | Fix polymorphic eager load with foreign_key as String.Lauro Caetano2014-05-201-2/+17
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | The foreign_key could be `String` and just doing `owners_map[owner_key]` could return `nil`. To prevent this bug, we should `to_s` both keys if their types are different. Fixes #14734.
* | | Prevented belongs_to: touch propagating up if there are no changes being savedBrock Trappitt2014-05-211-1/+1
| | |
* | | fix multiple hash preloads. Fixes #14994Aaron Patterson2014-05-201-6/+7
| | |
* | | Fixed the inferred table name for HABTM within a schemaEric Chahin2014-05-201-1/+1
| | | | | | | | | | | | Fixes #14824.