aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/nested_attributes.rb
Commit message (Collapse)AuthorAgeFilesLines
* Call build when extend with nested attributes definedAlireza Bashiri2018-08-021-1/+1
| | | | | | | | What? From now on when `accepts_nested_attributes_for` defined and `extend` option added the overwritten `build` method being called. [Alireza Bashiri, Martins Polakovs]
* Add update_only example to AR nested attributes doc [ci_skip]Felipe Oliveira2017-10-031-0/+12
|
* Clarify intentions around method redefinitionsMatthew Draper2017-09-011-3/+2
| | | | | | | | | Don't use remove_method or remove_possible_method just before a new definition: at best the purpose is unclear, and at worst it creates a race condition. Instead, prefer redefine_method when practical, and silence_redefinition_of_method otherwise.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* 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.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-2/+1
| | | | | | | | | | | | * 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
* More friendly exception in nested attributesKir Shatrov2017-05-221-1/+1
|
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-3/+3
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-71/+71
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Fix Remaining Case-In-Assignment Statement FormattingAlex Kitchens2016-09-061-8/+9
| | | | | | | | | Recently, the Rails team made an effort to keep the source code consistent, using Ruboco (bb1ecdcc677bf6e68e0252505509c089619b5b90 and below). Some of the case statements were missed. This changes the case statements' formatting and is consistent with changes in 810dff7c9fa9b2a38eb1560ce0378d760529ee6b and db63406cb007ab3756d2a96d2e0b5d4e777f8231.
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-7/+7
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* applies remaining conventions across the projectXavier Noria2016-08-061-5/+5
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-116/+116
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-16/+16
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-03-061-1/+1
|\ | | | | | | | | Conflicts: guides/source/association_basics.md
| * [ci skip] Fix `'id'` to be fixed-width fontyui-knk2016-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | As shown below, we should use <tt>...</tt> for string literal ``` $ echo "+'id'+" | rdoc --pipe <p>+&#39;id&#39;+</p> $ echo "<tt>'id'</tt>" | rdoc --pipe <p><code>&#39;id&#39;</code></p> ```
* | [ci skip] Improve the readability of documents of nested_attributesyui-knk2016-02-241-6/+14
|/
* Don't short-circuit reject_if procAndrew White2016-01-221-2/+12
| | | | | | | | | | | | | When updating an associated record via nested attribute hashes the reject_if proc could be bypassed if the _destroy flag was set in the attribute hash and allow_destroy was set to false. The fix is to only short-circuit if the _destroy flag is set and the option allow_destroy is set to true. It also fixes an issue where a new record wasn't created if _destroy was set and the option allow_destroy was set to false. CVE-2015-7577
* Extra caller details added to ActiveRecord::RecordNotFoundSameer Rahmani2015-07-211-1/+3
| | | | | | | | | | | | | | | | ActiveRecord::RecordNotFound modified to store model name, primary_key and id of the caller model. It allows the catcher of this exception to make a better decision to what to do with it. For example consider this simple example: class SomeAbstractController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404 private def redirect_to_404(e) return redirect_to(posts_url) if e.model == 'Post' raise end end
* Ensure that 'ActionController::Parameters' can still be passed to AR for ↵Thomas Walpole2015-07-181-0/+6
| | | | collection associations
* Ensure that `ActionController::Parameters` can still be passed to ARSean Griffin2015-07-181-0/+3
| | | | | | | | | | | | | | | | | | | | | Since nested hashes are also instances of `ActionController::Parameters`, and we're explicitly looking to work with a hash for nested attributes, this caused breakage in several points. This is the minimum viable fix for the issue (and one that I'm not terribly fond of). I can't think of a better place to handle this at the moment. I'd prefer to use some sort of solution that doesn't special case AC::Parameters, but we can't use something like `to_h` or `to_a` since `Enumerable` adds both. While I've added a trivial test case for verifying this fix in isolation, we really need better integration coverage to prevent regressions like this in the future. We don't actually have a lot of great places for integration coverage at the moment, so I'm deferring it for now. Fixes #20922.
* "maybe" => "may be"Waynn Lue2015-05-211-1/+1
|
* docs for updating nested attributes while creating parent record [cish6khan2015-05-181-0/+5
| | | | skip]
* fixed typoBenny Klotz2015-04-281-2/+2
|
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-1/+1
|
* Always perform validations on nested attribute associationsSean Griffin2015-01-301-0/+1
| | | | | | | Collection associations would have already been validated, but singular associations were not. Fixes #18735.
* Don't redefine autosave association callbacks in nested attrsSean Griffin2015-01-281-1/+0
| | | | | | | | These callbacks will already have been defined when the association was built. The check against `reflection.autosave` happens at call time, not at define time, so simply modifying the reflection is sufficient. Fixes #18704
* A quick pass through NestedAttributes' doc [ci skip]Robin Dupret2015-01-021-18/+20
|
* Add information about "allow_destroy" requiring an ID. [ci skip]George Millo2014-12-231-0/+3
| | | | | | | I just wasted an absurd amount of time trying to figure out why my model wasn't being deleted even though I was setting `_destroy` to true like the instructions said. Making the documentation a little bit clear so that someone like me doesn't waste their time in future.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | 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.
* Move types to the top level `ActiveRecord` namespaceSean Griffin2014-05-271-1/+1
| | | | | `ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`
* Refactoring .reflections public method.Arthur Neves2014-05-261-1/+0
| | | | | | 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.
* Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-2/+3
| | | | | | | | | 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
* Inline typecasting helpers from Column to the appropriate typesSean Griffin2014-05-201-1/+1
|
* [ci skip] Improve doc, fix grammatical issueAkshay Vishnoi2014-04-131-4/+4
|
* Renamed generated_feature_methods to generated_association_methods.kennyj2013-09-281-1/+1
|
* Restore the use of `#add_to_target` for nested attribute updates on existing ↵Ben Woosley2013-08-121-11/+10
| | | | | | | | | records, and don't bother updating the association if the update is going to be rejected anyway. This requires adding a `skip_callbacks` argument to `#add_to_target` so that we don't call the callbacks multiple times in this case, which is functionally an application of existing association data, rather than an addition of a new record to the association.
* Fix interactions between :before_add callbacks and nested attributes assignmentDr.(USA) Joerg Schray2013-08-121-10/+9
| | | | | Issue #1: :before_add callback is called when nested attributes assignment assigns to existing record if the association is not yet loaded Issue #2: Nested Attributes assignment does not affect the record in the association target when callback triggers loading of the association
* let the object stay in charge of internal cache invalidationAaron Patterson2013-06-131-6/+1
|
* Getting rid of the +automatic_inverse_of: false+ option in associations in favorwangjohn2013-06-081-0/+4
| | | | | of using +inverse_of: false+ option. Changing the documentation and adding a CHANGELOG entry for the automatic inverse detection feature.
* Created a method to automatically find inverse associations and cachewangjohn2013-05-071-0/+5
| | | | | | the results. Added tests to check to make sure that inverse associations are automatically found when has_many, has_one, or belongs_to associations are defined.
* Do not overwrite manually built records during one-to-one nested attribute ↵Olek Janiszewski2013-05-031-7/+32
| | | | | | | | | | | | | | | | | | | | | assignment For one-to-one nested associations, if you build the new (in-memory) child object yourself before assignment, then the NestedAttributes module will not overwrite it, e.g.: class Member < ActiveRecord::Base has_one :avatar accepts_nested_attributes_for :avatar def avatar super || build_avatar(width: 200) end end member = Member.new member.avatar_attributes = {icon: 'sad'} member.avatar.width # => 200
* Added a bang to the end of +raise_nested_attributes_record_not_found+wangjohn2013-04-061-3/+3
| | | | method to signify an exception possibly being raised.
* Fix my typoAlexey Muranov2013-03-121-1/+1
|
* Align indentation in commentsAlexey Muranov2013-03-121-15/+15
|
* Document nested attributes as hash of hashesAlexey Muranov2013-03-121-2/+26
| | | Document the possibility to use a hash of hashes for nested attributes for a one-to-many association (in addition to the documented possibility to use an array of hashes).