aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #19924 from iamvery/db-tasks-exit-statusSean Griffin2015-10-262-3/+9
|\ | | | | | | Explicitly exit with status "1" for create and drop failures
| * 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-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | * 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
| |
* | Do not omit parentheses [ci skip]Ryuta Kamizono2015-10-253-13/+13
| |
* | 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-232-1/+9
| |
* | 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-221-10/+5
|\ \ \ | | | | | | | | | | | | | | | | 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-221-10/+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-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-222-20/+11
|/ / / | | | | | | | | | | | | | | | 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-201-6/+5
|\ \ | | | | | | | | | | | | 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-041-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-201-1/+3
|\ \ \ | | | | | | | | Allow select using Arel and perform a count
| * | | Allow select with Arel and count as well as calculations with ArelRoque Pinel2015-06-301-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-201-1/+1
|\ \ \ \ | | | | | | | | | | | | | | | Set active_record config for always creating uuids in generators
| * | | | Set active_record config for always creating uuids in generatorsJon McCartie2015-10-201-1/+1
| | | | |
* | | | | 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-201-1/+1
|\ \ \ \ \ \ | |_|/ / / / |/| | | | | | | | | | | Fix find_by with association subquery issue
| * | | | | Don't cache arguments in #find_by if they are an ActiveRecord::Relationakihiro172015-10-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this commit, find_by doesn't cache arguments so that find_by with association subquery works correctly. Fixes #20817
* | | | | | Qualify column names in calculationSoutaro Matsumoto2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Column names inserted via `group` have to be qualified with table name.
* | | | | | Fix merge conflicts for #18856Sean Griffin2015-10-201-2/+10
|\ \ \ \ \ \
| * | | | | | Match table names exactly on MySQLMatt Jones2015-02-081-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `SHOW TABLES LIKE` command accepts metacharacters `%` and `_` in potentially unexpected ways. This can be avoided by querying `information_schema.tables` directly. Fixes #17897
* | | | | | | Don't add classes to the top level namespaceSean Griffin2015-10-201-13/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've been writing too much Rust. My mind is still in the mode of things being auto-namespaced based on the file...
* | | | | | | Merge pull request #21883 from tarzan/cache-key-too-preciseSean Griffin2015-10-201-2/+2
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Fix precision on cache_key
| * | | | | | | fixes #21815Maarten Jacobs2015-10-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default timestamp used for AR is `updated_at` in nanoseconds! (:nsec) This causes issues on any machine that runs an OS that supports nanoseconds timestamps, i.e. not-OS X, where the cache_key of the record persisted in the database (milliseconds precision) is out-of-sync with the cache_key in the ruby VM. This commit adds: A test that shows the issue, it can be found in the separate file `cache_key_test.rb`, because - model couldn't be defined inline - transactional testing needed to be turned off to get it to pass the MySQL tests This seemed cleaner than putting it in an existing testcase file. It adds :usec as a dateformat that calculates datetime in microseconds It sets precision of cache_key to :usec instead of :nsec, as no db supports nsec precision on timestamps
* | | | | | | | Do not cache prepared statements that are unlikely to have cache hitsSean Griffin2015-10-209-18/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, Rails makes no differentiation between whether a query uses bind parameters, and whether or not we cache that query as a prepared statement. This leads to the cache populating extremely fast in some cases, with the statements never being reused. In particular, the two problematic cases are `where(foo: [1, 2, 3])` and `where("foo = ?", 1)`. In both cases we'll end up quoting the values rather than using a bind param, causing a cache entry for every value ever used in that query. It was noted that we can probably eventually change `where("foo = ?", 1)` to use a bind param, which would resolve that case. Additionally, on PG we can change our generated query to be `WHERE foo = ANY($1)`, and pass an array for the bind param. I hope to accomplish both in the future. For SQLite and MySQL, we still end up preparing the statements anyway, we just don't cache it. The statement will be cleaned up after it is executed. On postgres, we skip the prepare step entirely, as an API is provided to execute with bind params without preparing the statement. I'm not 100% happy on the way this ended up being structured. I was hoping to use a decorator on the visitor, rather than mixing a module into the object, but the way Arel has it's visitor pattern set up makes it very difficult to extend without inheritance. I'd like to remove the duplication from the various places that are extending it, but that'll require a larger restructuring of that initialization logic. I'm going to take another look at the structure of it soon. This changes the signature of one of the adapter's internals, and will require downstream changes from third party adapters. I'm not too worried about this, as worst case they can simply add the parameter and always ignore it, and just keep their previous behavior. Fixes #21992.
* | | | | | | | Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2Sean Griffin2015-10-202-5/+8
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | Add stored procedure test in mysql2
| * | | | | | | | Add stored procedure test in mysql2Ryuta Kamizono2015-10-151-1/+4
| | | | | | | | |
| * | | | | | | | Make `AbstractMysqlAdapter#version` publicRyuta Kamizono2015-10-151-4/+4
| | | | | | | | |
* | | | | | | | | Merge pull request #21962 from kamipo/fix_tinyblobSean Griffin2015-10-203-11/+31
|\ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | Fix to correctly schema dump the `tinyblob`
| * | | | | | | | | Fix to correctly schema dump the `tinyblob`Ryuta Kamizono2015-10-153-11/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`. But `t.binary ... limit: 255` is generating SQL to `varchar(255)`. It is incorrect. This commit fixes this problem.
* | | | | | | | | | Changed the order of Association constraints from where->order->unscope to ↵kal2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | unscope->where->order
* | | | | | | | | | Merge pull request #22003 from yui-knk/remove_needless_require_asYves Senn2015-10-202-4/+0
|\ \ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | Delete needless `require 'active_support/deprecation'`
| * | | | | | | | | | Delete needless `require 'active_support/deprecation'`yui-knk2015-10-202-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `require 'active_support/rails'`, 'active_support/deprecation' is automatically loaded.
* | | | | | | | | | | Green version of moving the handling of supported arguments to `where`yui-knk2015-10-182-3/+3
|/ / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit follow up of 4d8f62d. The difference from 4d8f62d are below: * Change `WhereClauseFactory` to accept `Arel::Nodes::Node` * Change test cases of `relation_test.rb`
* | | | | | | | | | Revert "Move the handling of supported arguments to `where`"Rafael Mendonça França2015-10-172-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 4d8f62dcfa0a5157b3facbd71f75fc6639636347. Reason: This broke the build. Please recommit again when it is green.
* | | | | | | | | | Move the handling of supported arguments to `where`Sean Griffin2015-10-162-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `WhereClauseFactory` handles all other branches based on argument types, so the code fits more naturally here, and it's just where the responsibility belongs.
* | | | | | | | | | `where` raises ArgumentError on unsupported types.Jake Worth2015-10-161-0/+2
| |_|/ / / / / / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | [#20473]
* | | | | | | | | [ci skip] readonly options has been removedIgnatius Reza2015-10-161-2/+0
| | | | | | | | |
* | | | | | | | | Add deprecation warning to `ActiveRecord::Relation#update`Ted Johansson2015-10-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When passing an instance of `ActiveRecord::Base` to `#update`, it would internally call `#find`, resulting in a misleading deprecation warning. This change gives this deprecated use of `#update` its own, meaningful warning.