aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* | | early return on delete and destroy methodseileencodes2014-05-181-0/+2
|/ / | | | | | | | | | | When delete or destroy is called on all records nothing is deleted or destroyed. Intead of running through the code and still not deleteing anything, we should early return
* | Remove the assignment for real this time.Zachary Scott2014-05-161-2/+2
| | | | | | | | | | | | cc: https://github.com/rails/rails/commit/a11e2fcff8cdc9691b977d8330abe63024f8c732#commitcomment-6353614 and 0369dbf
* | prepend mutates the string so we can remove the assignmentRafael Mendonça França2014-05-161-1/+1
| |
* | Don't use Active Support where it is not needed.Rafael Mendonça França2014-05-141-1/+3
| | | | | | | | | | parent_name is a string of nil, never a blank string so we don't need to use presence.
* | Merge pull request #14871 from kassio/kb-fixes-namespaced-habtmRafael Mendonça França2014-05-141-1/+5
|\ \ | | | | | | | | | | | | | | | | | | Fix how to compute class name on habtm namespaced. Conflicts: activerecord/CHANGELOG.md
| * | Fix how to compute class name on habtm namespaced.Kassio Borges2014-05-131-1/+5
| | | | | | | | | | | | | | | | | | Thank's for @laurocaetano for the help with tests. :smiley: Fixes #14709
* | | remove count vareileencodes2014-05-131-4/+2
| | | | | | | | | | | | this change was unneccsary as nothing was gained from it
* | | rename delete_all_records to delete_or_nullify_all_recordseileencodes2014-05-133-8/+4
| | | | | | | | | | | | | | | | | | | | | Rename delete_all_records because this name better describes what the method is doing. We can then remove :all from the hm:t version and pull out the unoptimized call to load_target in delete_records and pass it directly.