aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Fix has_many assocation w/select load after createErnie Miller2012-10-051-1/+1
| | | | | | | | | | | | | | If you create a new record via a collection association proxy that has not loaded its target, and which selects additional attributes through the association, then when the proxy loads its target, it will inadvertently trigger an ActiveModel::MissingAttributeError during attribute writing when CollectionAssociation#merge_target_lists attempts to do its thing, since the newly loaded records will possess attributes the created record does not. This error also raises a bogus/confusing deprecation warning when accessing the association in Rails 3.2.x, so cherry-pick would be appreciated!
* Revert "Use flat_map { } instead of map {}.flatten"Santiago Pastorino2012-10-053-4/+4
| | | | | | | | | | | This reverts commit abf8de85519141496a6773310964ec03f6106f3f. We should take a deeper look to those cases flat_map doesn't do deep flattening. irb(main):002:0> [[[1,3], [1,2]]].map{|i| i}.flatten => [1, 3, 1, 2] irb(main):003:0> [[[1,3], [1,2]]].flat_map{|i| i} => [[1, 3], [1, 2]]
* Use flat_map { } instead of map {}.flattenSantiago Pastorino2012-10-053-4/+4
|
* Count returns 0 without querying if parent is not savedFrancesco Rodriguez2012-10-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Patches `CollectionAssociation#count` to return 0 without querying if the parent record is new. Consider the following code: class Account has_many :dossiers end class Dossier belongs_to :account end a = Account.new a.dossiers.build # before patch a.dossiers.count # SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL # => 0 # after a.dosiers.count # fires without sql query # => 0 Fixes #1856.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-09-281-24/+8
|\ | | | | | | | | Conflicts: actionpack/lib/action_view/helpers/asset_tag_helper.rb
| * fix AR::Associations::CollectionProxy#delete broken documentation [ci skip]Francesco Rodriguez2012-09-211-23/+2
| |
| * update AR::Associations::CollectionProxy#loaded? documentation [ci skip]Francesco Rodriguez2012-09-211-1/+6
| |
* | Fix destructive side effects from marshaling an association caused by ↵Jeremy Kemper2012-09-251-5/+2
|/ | | | 65843e1acc0c8d285ff79f8c9c49d4d1215440be
* Merge pull request #7251 from rails/integrate-strong_parametersDavid Heinemeier Hansson2012-09-185-30/+29
|\ | | | | Integrate strong_parameters in Rails 4
| * Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-165-29/+29
| |
| * Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-1/+0
| |
* | Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmtRafael Mendonça França2012-09-171-0/+14
|\ \ | |/ |/| Fix collection= on hm:t join models when unsaved
| * Fix collection= on hm:t join models when unsavedErnie Miller2012-09-171-0/+14
| | | | | | | | | | | | If assigning to a has_many :through collection against an unsaved object using the collection=[<array_of_items>] syntax, the join models were not properly created, previously.
* | Remove debug code :bomb:Rafael Mendonça França2012-09-161-1/+0
| |
* | Don't preserve SELECT columns on COUNTSteve Klabnik2012-09-161-1/+2
|/ | | | | | | | | | | | | | | | | | The COUNT clause of a finder_sql relationship is being rewritten from COUNT(*) to COUNT(table_name.*). This does not appear to be valid syntax in MySQL: ``` mysql> SELECT COUNT( table_name.* ) FROM `table_name`; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* ) FROM `table_name`' at line 1 ``` This fixes the bug, as well as adding tests so we don't re-introduce it in the future. Fixes #3956.
* Update documentation for CollectionProxyMarc-Andre Lafortune2012-09-121-8/+2
|
* Merge pull request #4976 from kreynolds/fix_eager_without_pkeyJon Leighton2012-09-071-1/+1
|\ | | | | Fix eagerly loading associations without primary keys
| * Fix eagerly loading associations without primary keysKelley Reynolds2012-02-091-1/+1
| |
* | Fix grammarJo Liss2012-08-301-3/+3
| |
* | Use inversed parent for first and last child of has_many associationbrainopia2012-08-181-1/+1
| |
* | Use method compilation for association methodsJon Leighton2012-08-105-64/+62
| | | | | | | | | | | | | | | | | | Method compilation provides better performance and I think the code comes out cleaner as well. A knock on effect is that methods that get redefined produce warnings. I think this is a good thing. I had to deal with a bunch of warnings coming from our tests, though.
* | DRY up handling of dependent optionJon Leighton2012-08-105-63/+22
| |
* | Unprivatise all the thingsJon Leighton2012-08-107-170/+156
| | | | | | | | | | | | Well, not all of them, but some of them. I don't think there's much reason for these methods to be private.
* | move dependency logic out of generated methodsJon Leighton2012-08-107-65/+64
| |
* | Clean up dependent option validation.Jon Leighton2012-08-104-14/+7
| | | | | | | | | | We don't need the complexity of to_sentence, and it shouldn't be a bang method.
* | Remove the dependent_restrict_raises option.Jon Leighton2012-08-103-23/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* | Fix #7191. Remove unnecessary transaction when assigning has_one associations.kennyj2012-08-081-13/+15
| |
* | removes usage of Object#in? from the code base (the method remains defined ↵Xavier Noria2012-08-062-10/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | by Active Support) Selecting which key extensions to include in active_support/rails made apparent the systematic usage of Object#in? in the code base. After some discussion in https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d we decided to remove it and use plain Ruby, which seems enough for this particular idiom. In this commit the refactor has been made case by case. Sometimes include? is the natural alternative, others a simple || is the way you actually spell the condition in your head, others a case statement seems more appropriate. I have chosen the one I liked the most in each case.
* | Changing AR:CollectionAssociation#empty? to use #exists?beerlington2012-08-051-3/+11
| | | | | | | | | | COUNT(*) queries can be slow in PostgreSQL, #exists? avoids this by selecting a single record.
* | load active_support/deprecation in active_support/railsXavier Noria2012-08-022-2/+0
| |
* | load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-025-5/+0
| |
* | load active_support/core_ext/object/blank in active_support/railsXavier Noria2012-08-021-1/+0
| |
* | s/scoped/scope/Jon Leighton2012-08-017-25/+31
| |
* | Add CollectionProxy#scopeJon Leighton2012-08-011-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This can be used to get a Relation from an association. Previously we had a #scoped method, but we're deprecating that for AR::Base, so it doesn't make sense to have it here. This was requested by DHH, to facilitate code like this: Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do @topics = @project.topics.scope @todolists = @project.todolists.scope @attachments = @project.attachments.scope @documents = @project.documents.scope end
* | Use explicit delegationsJon Leighton2012-08-011-119/+79
| | | | | | | | | | | | | | This makes it easier to see what the documentation refers to. It also means that we are not doing unnecessary work for delegations that have no args / splats / block / etc.
* | Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-013-1/+22
| |
* | Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-017-35/+111
| | | | | | | | | | | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* | Refactor dependency check validationCarlos Antonio da Silva2012-08-014-28/+19
| | | | | | | | | | | | Move the logic for validation check to the same method, and cache dependent option in a variable to reuse inside the dependency configuration methods instead of relying on the options hash.
* | move method for dependent option checkHrvoje Šimić2012-08-014-11/+22
| |
* | fix typo in collection proxyAccessd2012-07-311-1/+1
| |
* | Deprecate Relation#all.Jon Leighton2012-07-271-1/+1
| | | | | | | | | | | | It has been moved to active_record_deprecated_finders. Use #to_a instead.
* | Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-273-7/+3
| | | | | | | | | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* | Deprecate update_column in favor of update_columns.Rafael Mendonça França2012-07-241-1/+1
| | | | | | | | Closes #1190
* | we don't need this argJon Leighton2012-07-201-2/+2
| |
* | Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-207-111/+35
| |
* | Remove obsolete line.Jon Leighton2012-07-201-1/+0
| | | | | | | | | | | | | | | | This code is broken (it should say association_scope.uniq_value rather than options[:uniq]) but the tests still pass. I think it is designed to uniq-ify associations using finder_sql. However, I am about to remove that anyway.
* | Convert association macros to the new syntaxJon Leighton2012-07-201-1/+1
| |
* | Avoid options ever being nilJon Leighton2012-07-201-4/+4
| | | | | | | | This fixes active_record_deprecated_finders.
* | fix association :extend optionJon Leighton2012-07-133-12/+19
| |
* | move the deprecated options into active_record_deprecated_findersJon Leighton2012-07-132-5/+2
| |