aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-2/+2
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-121-1/+1
| | | | | | | | | | - we are ending sentences properly - fixing of space issues - fixed continuity issues in some sentences. Reverts https://github.com/rails/rails/commit/8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 . This change reverts making sure we add '.' at end of deprecation sentences. This is to keep sentences within Rails itself consistent and with a '.' at the end.
* start hiding the `scope_chain` data structureAaron Patterson2016-03-041-0/+10
| | | | | Introduce a predicate method that doesn't need to build a scope chain, but also hides the data structure used for representing the scope chain.
* don't build the reflection chain to calculate `nested?`Aaron Patterson2016-03-041-1/+9
| | | | | | | | We know a reflection can be considered as `nested?` if the source reflection or the through reflection are also through reflections (since the through reflection will also add another join table). This allows us to avoid traversing the entire reflection tree just to calculate whether or not there will be more join tables.
* remove useless ivarAaron Patterson2016-03-041-1/+0
|
* Respect through association scopes when used with polymorphicSean Griffin2016-02-291-1/+1
| | | | | | | | | | | When the `source_type` option is passed to a has_many through, the resulting `Reflection` will be an instance of `PolymorphicReflection` and not `ThroughReflection`, meaning that it will ignore the scopes that it needs to apply from the through reflections. This adds an additional delegation call to remedy this. I've been finding the reflection code completely impenetrable lately, it could use some major love. Fixes #22726
* build scope chain functionally and remove cachingAaron Patterson2016-02-101-14/+40
| | | | | | | This commit walks the reflection tree and builds the scope chain functionally. It also removes the chain cache since the cache doesn't seem to have any impact on performance (I'd prefer to only cache at proven bottlenecks)
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-02-071-10/+13
|\
| * fix indentationVijay Dev2016-02-071-1/+1
| |
| * [ci skip] Update internal documents about ActiveRecord's Reflectionyui-knk2016-01-301-11/+14
| | | | | | | | | | | | | | ActiveRecord's Reflection was refactored by f8d2899d12d59360f29c5eb6a1b1a8fe4ec82ca0 . Top of ancestors chain was changed to `AbstractReflection` from `MacroReflection`, and new Reflections were added.
* | Remove unnecessary overriding of `#initialize`yui-knk2016-02-021-12/+0
| | | | | | | | | | | | `#initialize` of `HasManyReflection`, `HasOneReflection` and `BelongsToReflection` only pass all arguments to `super` by passed order. These overriding can be removed.
* | Remove `case macro` from `calculate_constructable`yui-knk2016-02-011-8/+13
| | | | | | | | | | | | | | | | | | Rails has abstract Reflection classes (`MacroReflection`, `AssociationReflection` etc.) and concrete Reflection classes (e.g. `HasManyReflection`, `HasOneReflection` etc.). In many case `calculate_constructable` returns `true`, so change `calculate_constructable` to always return `true` and override this method if necessary.
* | Each concrete classes have responsibility to return `association_class`yui-knk2016-01-311-22/+25
| |
* | Merge branch '5-0-beta-sec'Aaron Patterson2016-01-251-2/+2
|\ \ | |/ |/| | | | | | | | | | | | | | | | | * 5-0-beta-sec: bumping version fix version update task to deal with .beta1.1 Eliminate instance level writers for class accessors allow :file to be outside rails root, but anything else must be inside the rails view directory Don't short-circuit reject_if proc stop caching mime types globally use secure string comparisons for basic auth username / password
| * Eliminate instance level writers for class accessorsAaron Patterson2016-01-221-2/+2
| | | | | | | | | | | | | | | | | | Instance level writers can have an impact on how the Active Model / Record objects are saved. Specifically, they can be used to bypass validations. This is a problem if mass assignment protection is disabled and specific attributes are passed to the constructor. CVE-2016-0753
* | [ci skip] `automatic_inverse_of` returns `false` not `nil` (document fix)yui-knk2016-01-091-1/+1
|/
* Freeze association foreign keys to reduce allocationsSean Griffin2015-11-151-1/+1
| | | | | | | | | | | | The string returned here will ultimately get used as a key of a hash in the attribute set once the attributes are being built. When you give a non-frozen string to `Hash#[]`, it will be duped. Be freezing we can significantly reduce the number of times we end up allocating `"user_id"` This does not include any additional tests, as this should not have any public facing implications. If you are mutating the result of `Reflection#foreign_key`, please stop.
* Wrong usage of 'a' in docs fixed [ci skip]Mehmet Emin İNAÇ2015-10-031-1/+1
|
* Fix regression in inverse_of on through associationseileencodes2015-09-261-14/+16
| | | | | | | | | | | | | | | | | | | `inverse_of` on through associations was accidently removed/caused to stop working in commit f8d2899 which was part of a refactoring on `ThroughReflection`. To fix we moved `inverse_of` and `check_validity_of_inverse!` to the `AbstractReflection` so it's available to the `ThroughReflection` without having to dup any methods. We then need to delegate `inverse_name` method in `ThroughReflection`. `inverse_name` can't be moved to `AbstractReflection` without moving methods that set the instance variable `@automatic_inverse_of`. This adds a test that ensures that `inverse_of` on a `ThroughReflection` returns the correct class name, and the correct record for the inverse relationship. Fixes #21692
* [ci skip] Remove useless "@api public/private"yui-knk2015-09-171-7/+1
| | | | Other public APIs do not have these annotations.
* Merge pull request #21486 from bogdan/refactor-has-many-counter-cacheEileen M. Uchitelle2015-09-091-9/+50
|\ | | | | HasManyAssociation: moved half of counter cache code to reflection