aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* If a counter_cache is defined, then using update_attributes and changingJohn Wang2013-03-151-0/+31
| | | | | the primary key on an association will make sure that the corresponding counter on the association is changed properly. Fixes #9722.
* Remove warningRafael Mendonça França2013-02-241-1/+1
|
* test case to prevent duplicated associations with custom PK.Yves Senn2013-02-241-0/+10
| | | | closes #9201
* Fix cases where delete_records on a has_many association caused errorsDerek Kraan2013-01-271-1/+19
| | | | | | | | | | | | | because of an ambiguous column name. This happened if the association model had a default scope that referenced a third table, and the third table also referenced the original table (with an identical foreign_key). Mysql requires that ambiguous columns are deambiguated by using the full table.column syntax. Postgresql and Sqlite use a different syntax for updates altogether (and don't tolerate table.name syntax), so the fix requires always including the full table.column and discarding it later for Sqlite and Postgresql.
* Revert "Merge pull request #8989 from robertomiranda/use-rails-4-find-by"Guillermo Iguaran2013-01-181-7/+7
| | | | | This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
* Merge pull request #8989 from robertomiranda/use-rails-4-find-byGuillermo Iguaran2013-01-181-7/+7
|\ | | | | Replace deprecated find_by_* with find_by
| * User Rails 4 find_byrobertomiranda2013-01-181-7/+7
| |
* | Undeprecate the :extend optionJon Leighton2013-01-181-0/+12
| | | | | | | | | | | | | | Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
* | CollectionProxy should be default scopedJon Leighton2013-01-181-0/+5
| | | | | | | | Fixes #8795
* | `CollectionAssociation#empty?` respects newly builded recordsYves Senn2013-01-131-0/+7
|/
* Move where with blank conditions test to the correct where tests fileCarlos Antonio da Silva2012-12-071-6/+0
| | | | This test does not belong to has many associations test.
* Ensure there won't be any regression with where(nil) callsCarlos Antonio da Silva2012-12-071-1/+1
| | | | | | | | | | | | | | | | | | | Consider this scenario: if params[:foo] conditions = { foo: true } end foos = Foo.where(conditions).order(:id) When params[:foo] is nil, this would call: foos = Foo.where(nil).order(:id) In this scenario, we want Foo.where(conditions) to be the same as calling Foo.all, otherwise we'd get a "NoMethodError order for WhereChain". Related to #8332.
* Merge pull request #8332 from amatsuda/ar_where_chainCarlos Antonio da Silva2012-12-071-1/+1
|\ | | | | | | | | | | | | | | Relation.where with no args can be chained with not, like, and not_like Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/query_methods.rb
| * Relation.where with no args can be chained with not, like, and not_likeAkira Matsuda2012-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | examples: Model.where.not field: nil #=> "SELECT * FROM models WHERE field IS NOT NULL Model.where.like name: 'Jeremy%' #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%' this feature was originally suggested by Jeremy Kemper https://github.com/rails/rails/pull/5950#issuecomment-5591330 Closes #5950
* | User assert_kind_of, invert assert_equal expectationsCarlos Antonio da Silva2012-11-291-3/+3
| |
* | Added STI support to init and building associationsJason Rush2012-11-291-0/+28
|/ | | | | | | | Allows you to do BaseClass.new(:type => "SubClass") as well as parent.children.build(:type => "SubClass") or parent.build_child to initialize an STI subclass. Ensures that the class name is a valid class and that it is in the ancestors of the super class that the association is expecting.
* Corrects typo in test nameAndy Lindeman2012-11-261-1/+1
|
* Merge pull request #8291 from senny/8265_build_with_polymorphic_associationRafael Mendonça França2012-11-221-0/+8
|\ | | | | | | | | | | | | prevent mass assignment of polymorphic type when using `build` Conflicts: activerecord/CHANGELOG.md
| * prevent mass assignment of polymorphic type when using `build`Yves Senn2012-11-221-0/+8
| | | | | | | | Closes #8265
* | Deprecate Relation#sum with a block.Carlos Antonio da Silva2012-11-211-0/+6
|/ | | | | | | To perform a sum calculation over the array of elements, use to_a.sum(&block). Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73 for more context.
* Test for has_many bug on unsaved recordsGeorge Brocklehurst2012-11-161-0/+7
| | | | See issue #7950.
* Merge and add tests related to 5215Vipul A M2012-11-121-6/+1
|
* Merge pull request #8116 from senny/7993_configure_counter_cache_for_has_manyJon Leighton2012-11-091-0/+8
|\ | | | | :counter_cache option for to support custom named counter caches
| * :counter_cache option for to support custom named counter caches. Closes #7993Yves Senn2012-11-041-0/+8
| |
* | Delegate all calculations to the scope.Jon Leighton2012-11-091-0/+1
| | | | | | | | | | | | | | So that the scope may be a NullRelation and return a result without executing a query. Fixes #7928
* | CollectionProxy#pluck issues no query for a new_record? ownerJon Leighton2012-11-091-0/+1
| | | | | | | | | | | | | | Fixes #8102. I couldn't find a nicer way to deal with this than delegate the call to #scope, which will be a NullRelation when we want it to be.
* | Relations built off collection associations with an unsaved owner should be ↵Jon Leighton2012-11-091-0/+9
|/ | | | | | | | | | null relations For example, the following should not run any query on the database: Post.new.comments.where(body: 'omg').to_a # => [] Fixes #5215.
* Count returns 0 without querying if parent is not savedFrancesco Rodriguez2012-10-031-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 pull request #7251 from rails/integrate-strong_parametersDavid Heinemeier Hansson2012-09-181-35/+0
|\ | | | | Integrate strong_parameters in Rails 4
| * Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-161-13/+0
| |
| * Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-22/+0
| |
* | Fix warning: method redefine. Testcase name are duplicated.kennyj2012-09-171-1/+1
|/
* Don't preserve SELECT columns on COUNTSteve Klabnik2012-09-161-1/+31
| | | | | | | | | | | | | | | | | | 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.
* Remove the dependent_restrict_raises option.Jon Leighton2012-08-101-24/+17
| | | | | | | | | | | | | | | 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.
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-1/+1
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-011-12/+28
|
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-011-0/+102
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* AR::Relation#order: make new order prepend old oneBogdan Gusiev2012-07-311-2/+2
| | | | | | | User.order("name asc").order("created_at desc") # SELECT * FROM users ORDER BY created_at desc, name asc This also affects order defined in `default_scope` or any kind of associations.
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-40/+40
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-14/+14
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Deprecate update_column in favor of update_columns.Rafael Mendonça França2012-07-241-3/+3
| | | | Closes #1190
* rm redundant testJon Leighton2012-07-201-7/+0
| | | | now everything is converted to the new style, this is not needed
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-201-102/+0
|
* Fix class_eval without __FILE__ and __LINE__.kennyj2012-07-181-2/+2
|
* Allow associations to take a lambda which builds the scopeJon Leighton2012-07-131-0/+7
|
* Remove ActiveRelation#inspectBrian Cardarella2012-06-291-1/+1
|
* No need to cache table metadata in advance now that #6683 was merged.Rafael Mendonça França2012-06-111-5/+0
|
* Merge pull request #6492 from pmahoney/fair-connection-pool2Rafael Mendonça França2012-06-111-0/+3
|\ | | | | | | | | | | | | Fair connection pool2 Conflicts: activerecord/test/cases/associations/eager_test.rb
| * Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-251-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The core of this fix is a threadsafe, fair Queue class. It is very similar to Queue in stdlib except that it supports waiting with a timeout. The issue this solves is that if several threads are contending for database connections, an unfair queue makes is possible that a thread will timeout even while other threads successfully acquire and release connections. A fair queue means the thread that has been waiting the longest will get the next available connection. This includes a few test fixes to avoid test ordering issues that cropped up during development of this patch.
* | Add support for CollectionAssociation#delete by Fixnum or StringFrancesco Rodriguez2012-05-281-3/+17
|/ | | | | | | | | | | | | | | | | | | | | | | | I found the next issue between CollectionAssociation `delete` and `destroy`. class Person < ActiveRecord::Base has_many :pets end person.pets.destroy(1) # => OK, returns the destroyed object person.pets.destroy("2") # => OK, returns the destroyed object person.pets.delete(1) # => ActiveRecord::AssociationTypeMismatch person.pets.delete("2") # => ActiveRecord::AssociationTypeMismatch Adding support for deleting with a fixnum or string like `destroy` method.