aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
Commit message (Collapse)AuthorAgeFilesLines
* remove deprecated support to preload instance-dependent associaitons.Yves Senn2015-01-051-6/+3
| | | | Addresses https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1#commitcomment-9145960
* Remove deprecated `Reflection#source_macro`Rafael Mendonça França2015-01-041-19/+0
|
* Cleanup methods, missing spacing and missing nodocseileencodes2015-01-021-14/+14
| | | | | | | | | | 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`
* Add `#all_includes` method to reflectionseileencodes2015-01-021-0/+2
| | | | | `yield` instead of relying on checking if the reflection is equal to the `chain_head`.
* Move `alias_candiate` into `AbstractReflection`eileencodes2015-01-021-1/+9
| | | | | | 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`.
* Assign the `#alias_name` to each reflectioneileencodes2015-01-021-7/+3
| | | | This makes the `#alias_name` more functional.
* Clean up / refactor new reflection classeseileencodes2015-01-021-42/+75
| | | | | | Move `RuntimeReflection` and `PolymorphicReflect` into Reflection. This allows the methods to inherit from `ThroughReflection` and DRY up the methods by removing duplicates.
* Move `#alias_name` to `ReflectionProxy` classeileencodes2015-01-021-10/+0
| | | | | Putting the `#alias_name` into ReflectionProxy means we don't have to cache the `#alias_name` globally anymore - it's not cached per query.
* Refactor construct_tables methodeileencodes2015-01-021-0/+10
| | | | | Move method structure into reflection classes for accessibly on each reflection rather than by traversing the chain.
* Add PolymorphicReflection and constraints methodeileencodes2015-01-021-1/+58
| | | | | | `#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 #15746 from amccloud/auto-inverse_of-in-moduleRafael Mendonça França2015-01-021-1/+1
|\ | | | | | | | | | | | | Fixed automatic inverse_of for models nested in module Conflicts: activerecord/CHANGELOG.md
| * Fixed automatic inverse_of for models nested in moduleAndrew McCloud2014-06-151-1/+1
| |
* | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-081-1/+1
| | | | | | | | | | | | | | 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.
* | Fix grammar of sentence in Reflection documentationeileencodes2014-12-071-3/+3
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| |
* | Update reflections public API docArthur Neves2014-11-221-1/+1
| |
* | Improve the performance of reading attributesSean Griffin2014-11-181-1/+1
| | | | | | | | | | | | | | 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`
* | let's warn with heredocsXavier Noria2014-10-281-11/+19
| | | | | | | | | | | | | | | | | | | | | | | | The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean.
* | Use if/else instead of early raiseRafael Mendonça França2014-10-151-2/+5
| |
* | Raise an error for has_one associations which try to go :through a ↵Tu Hoang2014-10-151-0/+1
| | | | | | | | polymorphic association [#17263]
* | Always add lambda to scope chain to eliminate branch in eval_scopeeileencodes2014-09-041-2/+5
| | | | | | | | | | | | 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.
* | Avoid using heredoc for user warningsGodfrey Chan2014-08-281-15/+14
| | | | | | | | | | | | | | | | | | | | Using heredoc would enforce line wrapping to whatever column width we decided to use in the code, making it difficult for the users to read on some consoles. This does make the source code read slightly worse and a bit more error-prone, but this seems like a fair price to pay since the primary purpose for these messages are for the users to read and the code will not stick around for too long.
* | [ci skip] "..enables interrorgating of [thing].." would be correctZachary Scott2014-08-191-1/+1
| |
* | Merge pull request #16377 from JackDanger/doc-fix-in-association-reflectionEileen M. Uchitelle2014-08-021-1/+1
|\ \ | | | | | | Fixes small error in ActiveRecord::Reflection docs
| * | Fixes small error in ActiveRecord::Reflection docsJack Danger Canty2014-07-311-1/+1
| | | | | | | | | | | | [ci skip]
* | | Deprecate source_macroeileencodes2014-08-021-1/+7
| | | | | | | | | | | | | | | | | | `source_macro` is no longer used in any ActiveRecord code. I've chosen to deprecate it because it was not marked as nodoc and may be in use outside of rails source.
* | | Refactor join_keys to remove complex conditionalseileencodes2014-07-311-21/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-9/+7
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | [ci skip] Fix documentation for @macro and reflection typeseileencodes2014-07-271-6/+9
| | | | | | | | | | | | | | | | 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`
* | create_join_table uses same logic as HABTM reflectionsStefan Kanev2014-07-181-1/+1
| | | | | | | | | | | | | | | | Before this change, create_join_table would not remove the common prefix in the join table name, unlike ActiveRecord::Reflections. A HABTM between Music::Artist and Music::Record would use a table music_artists_records, while create_join table would create music_artists_music_records.
* | Remove need for macro instance vareileencodes2014-07-171-11/+14
| | | | | | | | | | | | | | | | Same as we did for collection, removed the `@macro` instance var and it is now set in each association. Unfortunately it can't be left undefined in AssociationReflection so it has to be set there. For now I am setting it to NotImplementedError since there is no default macro and it changes based on the reflection type.
* | Begin refactoring ThroughReflectioneileencodes2014-07-081-66/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to decouple AssociationReflection and ThroughReflection making ThroughReflection it's own Reflection bucket in a way. The benefit of this is to be able to remove checks against the macro's symbol for exmaple `macro == :belongs_to`. Get all tests passing again Some of the methods that used to be inherited from MacroReflection through AssociationReflection were no longer getting passed through. They needed to be duplicated into the ThroughReflection. I will extract these out into a separate class. Refactor shared methods into strategy object Now that we've separated ThroughReflection and AssociationReflection we can combine shared methods into one class to avoid duplication. Break out class for each type of reflection This creates a class for each reflection type (has_many, has_one, belongs_to and habtm). We then can remove the need to set the macro symbol in each initialization. Tests were updated to reflect these changes because creation of these reflections is now different. Remove need for @collection instance var We now define `collection?` as `false` by default and set it to `true` in `has_and_belongs_to_many` and `has_many` reflections. This removes the need for the `@collection` instance variable. Raise exception on unknown macro types We shouldn't accept just any macro when creating reflections. An unrecongnized AssociationReflection raises an error. Tests in `reflection_test` were updated to reflect these new changes. `:has_and_belongs_to_many` macro tests were removed because we no longer internally return HABTM.
* | Don't rely on the column for type casting reflectionsSean Griffin2014-06-181-2/+2
|/
* Merge pull request #15343 from dontfidget/fix_polymorphic_automatic_inverse_ofRafael Mendonça França2014-06-131-1/+1
|\ | | | | prevent bad automatic inverse_of association
| * use name specified by 'as' for automatic inverse association to avoid ↵Andrew S. Brown2014-06-101-1/+1
| | | | | | | | reflecting on wrong association
* | Merge pull request #15630 from eileencodes/refactor-join-keys-on-add_constraintsMatthew Draper2014-06-121-0/+17
|\ \ | | | | | | begin refactoring add_constraints by moving join keys
| * | begin refactoring add_constraints by moving join keyseileencodes2014-06-101-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`.
* | | Add has_one? docs [skip ci]Arthur Neves2014-06-111-0/+1
|/ /
* | Use HasAndBelongsToMany instead of HABTMArthur Neves2014-06-091-1/+1
| |
* | reuse available collection? check instead of macroeileencodes2014-06-091-1/+1
| | | | | | | | | | | | | | 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`.
* | Merge pull request #15596 from eileencodes/add-has_one-method-and-reuseRafael Mendonça França2014-06-091-1/+5
|\ \ | | | | | | add has_one? method and reuse instead of checking macro
| * | add has_one? method and reuse instead of checking macroeileencodes2014-06-091-1/+5
| | | | | | | | | | | | | | | | | | 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.
* | | Abstract away use of HABTM macroeileencodes2014-06-091-1/+8
|/ / | | | | | | | | | | | | | | | | By having the `:has_and_belongs_to_many` macro in the `@collection` we are punishing `:has_many` associations because it has to allocate the array and check the macro. @collection is returned to `macro == :has_many` and a new reflection class `HABTMReflection` is created to handle this case instead.
* | fix polymorphic? method and reuse iteileencodes2014-06-021-8/+8
| | | | | | | | | | | | 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]`.
* | Refactoring .reflections public method.Arthur Neves2014-05-261-4/+23
| | | | | | | | | | | | Now the internal reflections will hold a reference to its public representation, so when the outside world calls `Account.reflection` we can build a list of public reflections.
* | Use .to_s on _reflections lookupArthur Neves2014-05-241-1/+1
| |
* | Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-7/+20
|/ | | | | | | | | 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
* deprecate, join, preload, eager load of instance dependent associations.Yves Senn2014-05-101-0/+14
| | | | | | | Closes #15024. These operations happen before instances are created. The current behavior is misleading and can result in broken behavior.
* Refactor AssociationScope#get_bind_valuesEric Chahin2014-05-051-0/+5
| | | | Added #join_id_for(owner) to reflection to avoid accessing the source_macro
* use statement cache for belongs_to relationsAaron Patterson2014-04-221-1/+4
|