aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix eager loading association with scope including joinsRyuta Kamizono2017-07-041-7/+11
| | | | Fixes #28324.
* 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.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Merge pull request #28808 from fschwahn/fix-polymorphic-automic-inverseMatthew Draper2017-07-011-4/+3
|\ \ | |/ |/| Fix automatic inverse for polymorphic interfaces
| * Remove :polymorphic from INVALID_AUTOMATIC_INVERSE_OPTIONSFabian Schwahn2017-04-201-4/+3
| | | | | | | | | | | | | | This makes automatic inverse detection possible for polymorphic :has_one & :has_many possible. This resolves a number of issues, eg. `touch: true` on polymorphic relationships (#16446) and automatically setting inverse associations on newly built objects (#15028, #21843).
* | Merge pull request #28928 from kamipo/remove_habtm_initializeRafael França2017-06-281-4/+0
|\ \ | | | | | | Remove `HasAndBelongsToManyReflection#initialize`
| * | Remove `HasAndBelongsToManyReflection#initialize`Ryuta Kamizono2017-04-291-4/+0
| |/ | | | | | | It is delegating `super` only.
* | Fix eager loading to respect `store_full_sti_class` settingRyuta Kamizono2017-06-291-1/+1
| |
* | Move building constraint to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-2/+11
| |
* | Move constructing polymorphic type to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-4/+7
| |
* | Move constructing join scope to `Reflection`Ryuta Kamizono2017-06-261-4/+11
| |
* | Extract `build_scope` and `predicate_builder` in `Reflection`Ryuta Kamizono2017-06-241-7/+10
| |
* | Don't expose methods and attrs for internal usageRyuta Kamizono2017-05-301-17/+19
| |
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-301-0/+4
|\ \ | | | | | | | | | Fix association with extension issues
| * | Fix association with extension issuesRyuta Kamizono2017-05-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-4/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* | Fix crashing on circular left join references with scopingRyuta Kamizono2017-05-241-1/+1
| | | | | | | | Follow up of #25702.
* | Add type caster to `RuntimeReflection#alias_name`Jon Moss2017-05-021-1/+1
| | | | | | | | | | Since we have been using this `Arel::Table` since 111ccc832bc977b15af12c14e7ca078dad2d4373, in order to properly handle queries, it's important that we properly type cast arguments.
* | Use `flat_map` rather than `map(&:...).flatten`Ryuta Kamizono2017-04-291-1/+1
|/
* `join_keys` no longer needs a class passed to itAaron Patterson2017-03-031-27/+30
| | | | | | 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.
* refactor so there is only one JoinKeys factory methodAaron Patterson2017-03-031-4/+15
|
* ask reflection for klass join reflectionAaron Patterson2017-03-031-0/+15
|
* Move join scopes on to the reflection objectAaron Patterson2017-03-031-0/+22
| | | | | | | Scopes can only ever be *not* reflection objects when they are passed in to the Reflection constructor. Given this fact, we can eliminate is_a checks and an intermediate array object by just asking the reflection object for join scopes.
* Fix collection_singular_ids= bugDaniel Colson2017-02-021-2/+2
| | | | | | | | | When the association's primary key is manually set as a symbol and called with an array of strings, CollectionAssociation#ids_writer fails to cast the ids to integers. This is because AssociationReflection#association_primary_key_type and ThroughReflection#association_primary_key_type return the incorrect type, since ModelSchema.type_for_attribute only accepts a string. The result is an ActiveRecord::RecordNotFound error.
* Avoid lambda scopes when possibleAaron Patterson2017-01-301-3/+1
| | | | | | | Lambda scopes require a bunch more work. Ideally the `scope` list would be a homogeneous collection. In this case, the reflection knows how to construct the right reflection for this join, so lets just construct that relation rather than instance execing to figure it out later.
* deprecate `scope_chain`Aaron Patterson2017-01-301-0/+2
|
* update comments and call `super`Aaron Patterson2017-01-301-24/+3
|
* remove caching until we prove it is requiredAaron Patterson2017-01-301-7/+3
|
* Fix `scopes` implementation on `PolymorphicReflection`Aaron Patterson2017-01-301-47/+12
| | | | `PolymorphicReflection` needs to be custom for handling scope lambdas
* Implement `scopes` method on each Reflectioneileencodes2017-01-301-5/+47
| | | | | Each reflection should be responsible for returning the scopes needed to query against the db.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2017-01-111-3/+3
|\ | | | | | | | | Conflicts: railties/lib/rails/generators.rb
| * `meta-data` --> `metadata`Jon Moss2016-12-311-3/+3
| | | | | | | | | | | | Removes space from the word; is now spelled in the standard way. [ci skip]
* | Improve deprecation message for deprecated reflection class nameRyuta Kamizono2017-01-101-1/+1
| |
* | Deprecate reflection class name to accept a classKir Shatrov2017-01-091-0/+11
| | | | | | | | | | | | | | | | The idea of `class_name` as an option of reflection is that passing a string would allow us to lazy autoload the class. Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary and creating possible circular dependencies.
* | Privatize unneededly protected methods in Active RecordAkira Matsuda2017-01-051-3/+1
| |
* | Raise error when has_many through is defined before through associationChris Holmes2017-01-041-0/+8
| | | | | | | | | | | | | | https://github.com/rails/rails/issues/26834 This change raises an error if a has_many through association is defined before the through association.
* | Raise when a through association has an ambiguous reflection nameRafael Mendonça França2016-12-291-9/+7
|/
* Resolve association class correctly when assigning ids on a through associationMatthew Draper2016-12-091-0/+4
|
* Add test for collection *_ids= setter when association primary key setDominic Cleal2016-11-241-0/+4
| | | | | | | | Fixes casting of IDs to the data type of the association primary key, rather than then the data type of the model's primary key. (Tests use a string primary key on the association, rather than an int.) Tests issue #20995
* Merge pull request #26905 from bogdanvlviv/docsAndrew White2016-11-131-1/+1
|\ | | | | Add missing `+` around a some literals.
| * Add missing `+` around a some literals.bogdanvlviv2016-10-271-1/+1
| | | | | | | | | | | | Mainly around `nil` [ci skip]
* | Allow `autosave: true` to be used with inverse ofSean Griffin2016-11-011-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the changes in #25337, double save bugs are pretty much impossible, so we can just lift this restriction with pretty much no change. There were a handful of cases where we were relying on specific quirks in tests that had to be updated. The change to has_one associations was due to a particularly interesting test where an autosaved has_one association was replaced with a new child, where the child failed to save but the test wanted to check that the parent id persisted to `nil`. I think this is almost certainly the wrong behavior, and I may change that behavior later. But ultimately the root cause was because we never remove the parent in memory when nullifying the child. This makes #23197 no longer needed, but it is what we'll do to fix some issues on 5.0 Close #23197
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | Merge pull request #25432 from ↵Eileen M. Uchitelle2016-10-251-3/+3
|\ \ | |/ |/| | | | | kamipo/polymorphic_reflection_is_not_using_methods_from_through_reflection `PolymorphicReflection` is not using the methods from `ThroughReflection`
| * `PolymorphicReflection` is not using the methods from `ThroughReflection`Ryuta Kamizono2016-06-211-3/+3
| | | | | | | | | | | | | | | | `ThroughReflection` initializes `@delegate_reflection` and delegate all public methods to `delegate_reflection`. But `PolymorphicReflection` does not initialize `@delegate_reflection`. It is enough to inherit `AbstractReflection` (using `alias_candidate` only).
* | explain why autosave= disables inverse_of [ci skip]Xavier Noria2016-10-071-0/+4
| |
* | RuboCop is 100% green :tada:Xavier Noria2016-09-021-12/+13
| |
* | Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-0/+4
|\ \ | | | | | | | | | Preserve readonly flag only for readonly association
| * | Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-0/+4
| |/ | | | | | | Fixes #24093