aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Fix merge conflicts from #19501Sean Griffin2015-10-294-23/+28
|\ | | | | | | | | | | | | | | I'm making this commit separately because this has failing tests and style nitpicks that I'd like to make as individual commits, to make the changes I'm making explicit. We still want a single merge commit at the end, however.
| * DRY up STI subclass logicCody Cutrer2015-03-244-22/+29
| | | | | | | | | | | | | | | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes now with fixed specs
* | tests, no every adapter supports "connection.version"Yves Senn2015-10-292-22/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This solves the following issue: ``` $ bin/test Using sqlite3 /Users/senny/Projects/rails/activerecord/test/cases/adapters/mysql2/sp_test.rb:16:in `<class:Mysql2StoredProcedureTest>': undefined method `version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007f8bab4b5b70> (NoMethodError) from /Users/senny/Projects/rails/activerecord/test/cases/adapters/mysql2/sp_test.rb:5:in `<top (required)>' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `require' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `block in require' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `require' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `each' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `require_files' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/minitest_plugin.rb:69:in `plugin_rails_init' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:73:in `block in init_plugins' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:71:in `each' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:71:in `init_plugins' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:122:in `run' from bin/test:19:in `<main>' ```
* | Merge pull request #18548 from ↵Sean Griffin2015-10-287-0/+116
|\ \ | | | | | | | | | | | | | | | sebjacobs/support-bidirectional-destroy-dependencies Add support for bidirectional destroy dependencies
| * | Add support for bidirectional destroy dependenciesSeb Jacobs2015-01-167-1/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit if you defined a bidirectional relationship between two models with destroy dependencies on both sides, a call to `destroy` would result in an infinite callback loop. Take the following relationship. class Content < ActiveRecord::Base has_one :content_position, dependent: :destroy end class ContentPosition < ActiveRecord::Base belongs_to :content, dependent: :destroy end Calling `Content#destroy` or `ContentPosition#destroy` would result in an infinite callback loop. This commit changes the behaviour of `ActiveRecord::Callbacks#destroy` so that it guards against subsequent callbacks. Thanks to @zetter for demonstrating the issue with failing tests[1]. [1] rails#13609
* | | Fix Typo in EagerLoadPolymorphicError [ci skip]Alex Myers2015-10-271-1/+1
| | |
* | | Merge pull request #18383 from ↵Rafael Mendonça França2015-10-273-1/+40
|\ \ \ | | | | | | | | | | | | | | | | | | | | scambra/habtm-with-where-includes-16032-for-master Includes HABTM returns correct size now
| * | | Includes HABTM returns correct size now. It's caused by the join dependencySergio Cambra2015-01-073-2/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
* | | | fix typo in `db:purge` description [ci skip]yuuji.yaginuma2015-10-281-1/+1
| | | |
* | | | [ci skip] Aline code examples in AR changelogyui-knk2015-10-271-17/+14
| | | |
* | | | Revert "Merge pull request #21994 from mtodd/inherit-scopes"Rafael Mendonça França2015-10-272-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 60c9701269f5b412849f1a507df61ba4735914d7, reversing changes made to 6a25202d9ea3b4a7c9f2d6154b97cf8ba58403db. Reason: Broken build
* | | | Make inherited scope test failMatt Todd2015-10-262-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This triggers the JoinDependency work to reflect on the associations and trigger an error as follows: ActiveRecord::ConfigurationError: Association named 'account' was not found on Company; perhaps you misspelled it? Fix Company.of_first_firm joins association name Should be `Company.joins(:accounts)` not `Company.joins(:account)`. Do the same for Client.of_first_firm
* | | | [ci skip] Add doc for preloader_forschneems2015-10-261-0/+4
| | | |
* | | | [ci skip] Clarify doc for preloaders_for_oneschneems2015-10-261-0/+5
| | | |
* | | | [ci skip] Add doc to preloaders_onschneems2015-10-261-0/+1
| | | |
* | | | Merge pull request #19686 from tsun1215/index_errorsSean Griffin2015-10-267-4/+91
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | Errors can be indexed with nested attributes Close #8638
| * | | | Errors can be indexed with nested attributesMichael Probber2015-04-177-4/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `has_many` can now take `index_errors: true` as an option. When this is enabled, errors for nested models will be returned alongside an index, as opposed to just the nested model name. This option can also be enabled (or disabled) globally through `ActiveRecord::Base.index_nested_attribute_errors` E.X. ```ruby class Guitar < ActiveRecord::Base has_many :tuning_pegs accepts_nested_attributes_for :tuning_pegs end class TuningPeg < ActiveRecord::Base belongs_to :guitar validates_numericality_of :pitch end ``` - Old style - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - New style (if defined globally, or set in has_many_relationship) - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` [Michael Probber, Terence Sun]
* | | | | Merge pull request #19924 from iamvery/db-tasks-exit-statusSean Griffin2015-10-265-5/+15
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Explicitly exit with status "1" for create and drop failures
| * | | | | Update changelog with db rake task exit status fixJay Hayes2015-10-201-0/+4
| | | | | |
| * | | | | Exit with non-zero status when db:drop failsJay Hayes2015-10-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * If the drop task fails for a reason other than the database not existing, processing should end. This is indicated by a non-zero exit status. * Since the backtrace is already printed to screen, we forgo printing it again by using an explicit call to `exit`. * :warning: This modifies the behavior of the db:create task slightly in that the stack trace is no longer printed by default. If the `--trace` option is used, it will print the trace _after_ the error message.
| * | | | | Exit with non-zero status when db:create failsJay Hayes2015-10-203-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * If the create task fails for a reason other than the database already existing, processing should end. This is indicated by a non-zero exit status. * Since the backtrace is already printed to screen, we forgo printing it again by using an explicit call to `exit`. * :warning: This modifies the behavior of the db:create task slightly in that the stack trace is no longer printed by default. If the `--trace` option is used, it will print the trace _after_ the error message.
| * | | | | Fix test of drop failureJay Hayes2015-10-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Previously the sqlite3 adapter could not "fail" on drop. Now an error is raised when no file exists. * Also updates purge to be resilient of drop failures. This is how purge is expected to behave.
* | | | | | [ci skip] Fix method documentation locationschneems2015-10-261-3/+2
| | | | | |
* | | | | | Merge pull request #22064 from kamipo/do_not_omit_parenthesesSean Griffin2015-10-253-13/+13
|\ \ \ \ \ \ | | | | | | | | | | | | | | Do not omit parentheses [ci skip]
| * | | | | | Do not omit parentheses [ci skip]Ryuta Kamizono2015-10-253-13/+13
| | | | | | |
* | | | | | | Tweaked wording used in some tests.Sebastian McKenzie2015-10-251-4/+4
|/ / / / / /
* | | | | | Stop aligning the argumentsRafael Mendonça França2015-10-231-4/+4
| | | | | |
* | | | | | Use thor class_option to make the primary_key_type option workRafael Mendonça França2015-10-234-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | Also move the method to the right class
* | | | | | Move default uuid generation to active_recordJon McCartie2015-10-233-3/+12
| | | | | |
* | | | | | Remove no need `binds.empty?` checkingRyuta Kamizono2015-10-231-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `#exec_stmt` is private method and only called in `#exec_query`. it means `binds` is provided always. No need `binds.empty?` checking.
* | | | | | Merge pull request #21918 from bogdan/refactor-preloaderSean Griffin2015-10-221-42/+30
|\ \ \ \ \ \ | | | | | | | | | | | | | | Refactored association preloader for performance
| * | | | | | Refactored association preloader for performanceBogdan Gusiev2015-10-221-42/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * less arrays created * less complexity with only one level of nesting in loop
* | | | | | | Merge pull request #21950 from ↵Andrew White2015-10-224-11/+17
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rafaelsales/issues/21922-fix-ar-group-by-attribute-lookup Fix generated projection fields in group by query
| * | | | | | | Refactor Calculations#execute_grouped_calculation and clean AR test caseRafael Sales2015-10-222-11/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * When tried to use `Company#accounts` test/models/company.rb I got: ``` ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: accounts.company_id: SELECT COUNT(*) AS count_all, "companies"."firm_id" AS companies_firm_id FROM "companies" INNER JOIN "accounts" ON "accounts"."company_id" = "companies"."id" GROUP BY "companies"."firm_id" ``` * The refactor on Calculations class was just to simplify the code
| * | | | | | | Fix generated projection fields in group by queryRafael Sales2015-10-223-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Closes #21922 Let `Book(id, author_id)`, `Photo(id, book_id, author_id)` and `Author(id)` Running `Book.group(:author_id).joins(:photos).count` will produce: * Rails 4.2 - conflicts `author_id` in both projection and group by: ```sql SELECT COUNT(*) AS count_all, author_id AS author_id FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id" GROUP BY author_id ``` * Master (9d02a25) - conflicts `author_id` only in projection: ```sql SELECT COUNT(*) AS count_all, author_id AS author_id FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id" GROUP BY "books"."author_id" ``` * With this fix: ```sql SELECT COUNT(*) AS count_all, "books"."author_id" AS books_author_id FROM "books" INNER JOIN "photos" ON "photos"."book_id" = "books"."id" GROUP BY "books"."author_id" ```
* | | | | | | | Remove `#tables` extra args againRyuta Kamizono2015-10-224-24/+14
|/ / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This issue was resolved by #21687 already. But re-add args by #18856. `#tables` extra args was only using by `#table_exists?`. This is for internal API. This commit will remove these extra args again.
* | | | | | | Extract native getter to attr_reader.jbranchaud2015-10-211-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The getter is doing nothing more than returning the ivar, so it can be extracted to an attr_reader.
* | | | | | | move documentation of column options to `add_column`. Closes #20400.Yves Senn2015-10-212-79/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [ci skip] It's been a source of confusion that the lower-level `add_column` referenced the higher level `column` method for available options. `column` supports additional functionality like `index: true` that is not present on `add_column`. This patch moves common option documentation to `add_column` and only documents the additional options in `column`.
* | | | | | | typoScott Nelson2015-10-201-1/+1
| |/ / / / / |/| | | | |
* | | | | | Fix merge conflicts for #19938Sean Griffin2015-10-206-6/+29
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a separate commit, as it is not just a changelog conflict. Want to point out the changes in the code
| * | | | | | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-046-6/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems
* | | | | | | Merge pull request #20653 from repinel/allow-arel-select-countSean Griffin2015-10-202-1/+55
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Allow select using Arel and perform a count
| * | | | | | | Allow select with Arel and count as well as calculations with ArelRoque Pinel2015-06-302-1/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It allows a query like `User.select(:name).count` to be written using Arel as `User.select(User.arel_table[:name]).count`. It exposes the calculations API to accept Arel nodes: `User.count(User.arel_table[:name])`, `User.sum(User.arel_table[:id])`, `Account.average(Account.arel_table[:credit_limit])`, `Account.maximum(Account.arel_table[:credit_limit])` and `Account.minimum(Account.arel_table[:credit_limit])`.
* | | | | | | | Merge pull request #21762 from jmccartie/jm/uuidSean Griffin2015-10-202-1/+8
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | Set active_record config for always creating uuids in generators
| * | | | | | | | Set active_record config for always creating uuids in generatorsJon McCartie2015-10-202-1/+8
| | | | | | | | |
* | | | | | | | | Merge pull request #20934 from maurogeorge/migration-transformations-docSean Griffin2015-10-201-15/+51
|\ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add missed available transformations to Migration Doc [ci skip]
| * | | | | | | | | Add missed Available transformations to migration DocMauro George2015-07-221-15/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [ci skip]
* | | | | | | | | | Merge pull request #20957 from akihiro17/find-by-issueSean Griffin2015-10-203-1/+13
|\ \ \ \ \ \ \ \ \ \ | |_|/ / / / / / / / |/| | | | | | | | | | | | | | | | | | | Fix find_by with association subquery issue
| * | | | | | | | | Don't cache arguments in #find_by if they are an ActiveRecord::Relationakihiro172015-10-063-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this commit, find_by doesn't cache arguments so that find_by with association subquery works correctly. Fixes #20817
* | | | | | | | | | Fix test failures caused by d99db6b8b3e4Sean Griffin2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I messed up the merge conflict, and accidentally removed a schema query that needed to be ignored.