Commit Graph

775 Commits

Author SHA1 Message Date
Jay Hayes
22f80ae57b Explicitly exit with status "1" for create and drop failures
* A non-zero exit status allows subsequent shell commands to be chained
  together such as: `rake db:reset test:prepare && rspec && cap deploy`
  (if you're feeling brave :)
* Any exceptions raised during the `create` and `drop` tasks are caught
  in order to print a "pretty" message to the user. Unfortunately doing
  so prevents rake from aborting with a non-zero exit status to the shell.
* Therefore we re-raise the exceptions after the "pretty" message and
  re-catch them in the task.
* From the task we explicitly exit with a non-zero status. This method
  was chosen (rather than just letting rake fail from the exception) so
  that the backtrace is suppressed and the output to stderr is
  unchanged.
* Update activerecord CHANGELOG
2013-11-11 07:54:30 -06:00
Yves Senn
db56c0fcf5 tidy Active Record CHANGELOG. [ci skip]. 2013-11-11 12:03:36 +01:00
Denis Redozubov
3ed5642e69 Fixes problem with replacing has_one association record with itself 2013-11-11 14:19:12 +04:00
Carlos Antonio da Silva
5deec016fe Improve changelogs formatting [ci skip] 2013-11-09 16:44:58 -02:00
Yves Senn
97f0d9a0dd log bind variables after they were type casted.
The log output used to be confusing in situation where type casting has
"unexpected" effects. For example when finding records with a `String`.

BEFORE:

irb(main):002:0> Event.find("im-no-integer")
D, [2013-11-09T11:10:28.998857 #1706] DEBUG -- :   Event Load (4.5ms)  SELECT "events".* FROM "events" WHERE "events"."id" = $1 LIMIT 1  [["id", "im-no-integer"]]

AFTER:

irb(main):002:0> Event.find("im-no-integer")
D, [2013-11-09T11:10:28.998857 #1706] DEBUG -- :   Event Load (4.5ms)  SELECT "events".* FROM "events" WHERE "events"."id" = $1 LIMIT 1  [["id", 0]]
2013-11-09 11:23:34 +01:00
Jason Ayre
746d286026 revised changelog comment to be less than 80 chars 2013-11-07 07:57:13 -07:00
Jason Ayre
83689bec77 add autoload :TransactionState to fix Marshal.load issues 2013-11-07 07:57:13 -07:00
Carlos Antonio da Silva
caf2390aee Fix changelog indent [ci skip] 2013-11-04 12:42:47 -02:00
David Heinemeier Hansson
430b252d3d Revert "ActiveRecord::Base#<=> has been removed. Primary keys may not be in order," -- will be replaced with a check to ensure that the keys used for comparison are integers, and only fail if they are not.
This reverts commit 6256734e2d0bdd89f4b5d11da259d40afa0c95c7.

Conflicts:
	activerecord/CHANGELOG.md
2013-11-02 19:56:58 -07:00
David Heinemeier Hansson
f950b2699f Added ActiveRecord::QueryMethods#rewhere which will overwrite an existing, named where condition. 2013-11-02 17:36:45 -07:00
Rafael Mendonça França
4d7080f80c unscope now works on default_scope after 94924dc32baf78f13e289172534c2e71c9c8cade 2013-11-02 22:11:20 -02:00
David Heinemeier Hansson
e94e97ca79 Extend ActiveRecord::Base#cache_key to take an optional list of timestamp attributes of which the highest will be used. 2013-11-02 16:05:19 -07:00
Carlos Antonio da Silva
6963e8959f Fix to work on Ruby 1.9.3, example and changelog improvements 2013-11-02 18:08:37 -02:00
David Heinemeier Hansson
db41eb8a6e Added ActiveRecord::Base#enum for declaring enum attributes where the values map to integers in the database, but can be queried by name 2013-11-02 12:01:31 -07:00
Rafael Mendonça França
1918b12c04 Fix wrong behavior where associations with dependent: :destroy options
was using nullify strategy

This caused a regression in applications trying to upgrade.

Also if the user set the dependent option as destroy he expects to get
the records removed from the database.
2013-11-01 19:04:30 -02:00
Alan Kennedy
f74a5616e8 Save has_one associations only if record has changes
Prevents save related callbacks such as `after_commit` being
triggered when `has_one` objects are already persisted and have no
changes.
2013-10-31 18:16:29 +00:00
Yves Senn
ea296fcc2b no need for a CHANGELOG entry. [ci skip]. 2013-10-30 18:21:56 +01:00
Yves Senn
d0ea5c5b20 fix code typo in MysqlAdapter .Closes #12647. 2013-10-30 18:12:26 +01:00
Jan Bernacki
510601ce8e short arrays in inspect 2013-10-30 08:47:54 +04:00
David Heinemeier Hansson
8bf3411de9 Fix typo 2013-10-27 19:49:15 -07:00
Rafael Mendonça França
6fb056e3b6 Merge pull request #12578 from jeradphelps/configurable_schema_migrations_table_name
Configurable name for schema_migrations table

Conflicts:
	activerecord/CHANGELOG.md
2013-10-27 21:07:03 -02:00
Paul Nikitochkin
6b71a1416c Skip include_values from through associations chains for building target scope
Fixes: #12242, #9517, #10240
2013-10-27 21:15:41 +02:00
Jerad Phelps
26638f0ac9 added schema_migrations_table_name to ActiveRecord::Base in order that the name of the schema migrations table can be configured.
consolidated test_schema_migrations_table_name tests

Added changelog entry

edited changelog

removed commented lines

removed reader

ensure the schema migrations table is reset at end of test

added entry to configuration guide

guides typo and changelog order
2013-10-27 08:50:35 -05:00
Severin Schoepke
c3606afb2a cast json values on write to be consistent with reading from the db.
See also commit 5ac2341fab689344991b2a4817bd2bc8b3edac9d
2013-10-25 17:05:42 +02:00
Yves Senn
0492ea6d39 ActiveRecord::Store works together with PG hstore columns.
This is necessary because as of 5ac2341 `hstore` columns are always stored
as `Hash` with `String` keys. `ActiveRecord::Store` expected the attribute to
be an instance of `HashWithIndifferentAccess`, which led to the bug.
2013-10-25 08:35:35 +02:00
Yves Senn
bf43b4c33f stored_attributes need to be specific to a subclass.
Currently they are all stored globally in the same `Hash`.
This commit forces the creation of a per-class variable if necessary.

The behavior was exposed through the following test-case:

```
  1) Failure:
StoreTest#test_all_stored_attributes_are_returned [/Users/senny/Projects/rails/activerecord/test/cases/store_test.rb:151]:
--- expected
+++ actual
@@ -1 +1 @@
-[:color, :homepage, :favorite_food]
+[:resolution, :color, :homepage, :favorite_food]
```
2013-10-25 08:35:35 +02:00
Rafael Mendonça França
7160ffbe59 Merge pull request #12621 from laurocaetano/fix_has_one_association_with_primary_key_set
Save association when primary key is manually set

Conflicts:
	activerecord/CHANGELOG.md
2013-10-24 22:37:29 -02:00
laurocaetano
8022fc4913 Save association when primary key is manually set 2013-10-24 22:30:30 -02:00
Rafael Mendonça França
8f6e6e3e59 Add CHANGELOG entry for #12635 [ci skip] 2013-10-24 19:33:26 -02:00
Yves Senn
99044beb81 minor Active Record CHANGELOG cleanup. [ci skip]. 2013-10-22 09:36:49 +02:00
Rafael Mendonça França
b98c10c164 Merge pull request #12588 from jetthoughts/12586_subquery_with_unprepared_sql
Inline bind values for sub-queries generated for Relation in where

Conflicts:
	activerecord/CHANGELOG.md
2013-10-21 19:13:04 -02:00
Kevin Mook
a733e00b10 Fix loading a sql structure file on postgres when the file's path has whitespace in it 2013-10-21 13:30:05 -04:00
Eric Hankins
b057765817 Allow unscope to work with where.not
Allows you to call #unscope on a relation with negative equality operators,
i.e. Arel::Nodes::NotIn and Arel::Nodes::NotEqual that have been generated
through the use of where.not.
2013-10-21 09:43:57 -05:00
Shimpei Makimoto
e2419a451a Raise an exception when model without primary key calls .find_with_ids 2013-10-21 17:07:47 +09:00
Paul Nikitochkin
a2ed5d2381 Process sub-query relation's binding values
Generated sub-query for Relation as array condition for `where` method
did not take in account its bind values, in result generates invalid SQL query.

Fixed by adding sub-query relation's binding values to base relation

Closes: #12586
2013-10-20 21:07:07 +03:00
Szymon Nowak
4ba9c508ec In Relation#empty? use #exists? instead of #count. 2013-10-19 21:53:45 +02:00
Kenta Okamoto
bc5148da3d Convert Fixnum into String the port number in MySQL 2013-10-18 21:56:59 +09:00
Lucas Mazza
2f1c9c8d60 Fix code blocks identation on AR and AS CHANGELOGs 2013-10-16 10:53:43 -03:00
Rafael Mendonça França
9f80937e82 Merge pull request #12547 from derekprior/dp-fix-null-relation-pluck
Pluck on NullRelation should accept a list of columns
2013-10-15 12:09:46 -07:00
Vijay Dev
e3e3851ed6 grammar fix (reverted in e9a1ecd) 2013-10-15 23:34:59 +05:30
Derek Prior
23dfc39ed9 Pluck on NullRelation accepts a list of columns
`pluck` was updated to accept a list of columns, but the `NullRelation`
was never updated to match that signature. As a result, calling `pluck`
on a `NullRelation` results in an `ArgumentError`.
2013-10-15 13:11:43 -04:00
Neeraj Singh
cd9592959f scope_chain should not be mutated for other reflections
Currently `scope_chain` uses same array for building different
`scope_chain` for different associations. During processing
these arrays are sometimes mutated and because of in-place
mutation the changed `scope_chain` impacts other reflections.

Fix is to dup the value before adding to the `scope_chain`.

Fixes #3882.
2013-10-14 11:59:59 -04:00
Rafael Mendonça França
25649c7fd7 Merge pull request #9499 from dmitry/inverse_instance_should_not_be_reloaded_after_stale_state_change
Inversed instance should not be reloaded after stale state was changed

Conflicts:
	activerecord/CHANGELOG.md
2013-10-14 12:17:40 -03:00
Yves Senn
a11ddbe55f cleanup changelog entry format. [ci skip] 2013-10-14 09:47:21 +02:00
Dmitry Polushkin
04e3b41e2f Add a note to the changelog for #9499 2013-10-13 21:54:07 +01:00
Rafael Mendonça França
95cb54a29e Merge pull request #12508 from jetthoughts/12415_generate_subqueries_for_relation_from_binding_params
Generate subquery for Relation passed as array condition for where

Conflicts:
	activerecord/CHANGELOG.md
2013-10-13 16:45:30 -03:00
Paul Nikitochkin
bc293ff690 Generate subquery for Relation passed as array condition for where
Instead of executing 2 queries for fetching records filtered by array condition with Relation,
added generation of subquery to current query.

This behaviour will be consistent when passes Relation as hash condition to where

Closes: #12415
2013-10-13 22:13:50 +03:00
Rafael Mendonça França
c56dc753b4 Merge pull request #12511 from jetthoughts/informative_raise_message_for_incorrect_association
Make missed association exception message more informative
2013-10-13 12:01:27 -07:00
Paul Nikitochkin
625cd69a8b Make missed association exception message more informative
Add target class name, which should have missed association on preload,
into exception message to simplify detecting problem part.
2013-10-13 21:56:44 +03:00
Edo Balvers
7cab255a97 Fixes #11773 when using includes combined with select, the select statement was overwritten. 2013-10-08 16:41:53 +02:00
Vipul A M
a4f086dd9d intiantiated => instantiated [ci-skip] 2013-10-03 10:46:41 +05:30
Aaron Patterson
244446fcc5 add a note to the changelog 2013-10-02 16:06:59 -07:00
Yves Senn
dfe40cdcab unify Fixes notes in AR changelog. [ci skip]. 2013-10-02 15:36:20 +02:00
Yves Senn
032998ad74 change the savepoint interface to allow passing the name. 2013-09-30 15:29:40 +02:00
Yves Senn
12720c77f5 Make .next_migration_number reusable for third party AR generators. 2013-09-30 15:03:55 +02:00
Paul Nikitochkin
8fb0de2cae Removed where_values_hash from AR::NullRelation
In order to build associated records for owners which has not been saved
need to get where values to use as default attributes.
But for new record owner uses `ActiveRecord::NullRelation` which
override `where_values_hash` to return empty hash stub.

`where_values_hash` is not used to invoke any sql query, but good to
build others chains (even will be never executed) like:

```ruby
  post          = Post.new
  admin_comment = post.admin_comments.build

  assert_equal 'Admin', admin_comment.author
```

Closes #11376, #11676, #11675
2013-09-28 11:21:34 +03:00
Arthur Neves
dfd3b8096e changelog entry 2013-09-25 19:19:10 -04:00
Arthur Neves
25ada9b541 update changelog for #12359 2013-09-25 14:46:24 -04:00
kennyj
8dd5a582f5 ActiveRecord::ConnectionAdapters::Column.string_to_time method respects string with timezone. Closes #12278. 2013-09-25 00:08:40 +09:00
Rafael Mendonça França
16c7873c44 Merge pull request #9860 from wangjohn/update_attributes_throws_error_with_nil
Raising an error when nil is passed to update_attributes.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-24 11:56:50 -03:00
kennyj
bb54fcdfad Deprecate unused quoted_locking_column method. 2013-09-24 21:56:52 +09:00
Rafael Mendonça França
afcca464db Merge pull request #11382 from kennyj/fix_10751-2
Dump UUID default functions to schema.rb [2nd version]. Fixes #10751.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-22 16:01:01 -03:00
Rafael Mendonça França
70ff256850 Give the credits [ci skip] 2013-09-22 14:41:54 -03:00
Rafael Mendonça França
7f2e64520f Merge pull request #10500 from kennyj/fix_10450
Fixed a bug in  when using has_many association with :inverse_of option and UUID primary key.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-22 14:38:39 -03:00
Aaron Patterson
6256734e2d ActiveRecord::Base#<=> has been removed. Primary keys may not be in order,
or even be numbers, so sorting by id doesn't make sense.  Please use `sort_by`
and specify the attribute you wish to sort with.  For example, change:

  Post.all.to_a.sort

to:

  Post.all.to_a.sort_by(&:id)
2013-09-18 16:09:13 -07:00
Rafael Mendonça França
ae297710dd Merge pull request #12011 from jetthoughts/11963_fix_join_with_association_scope
Collapse where constraints to the Arel::Nodes::And node

Conflicts:
	activerecord/CHANGELOG.md
2013-09-16 13:45:25 -03:00
Paul Nikitochkin
fbbb6c87fd Collapse where constraints to one where constraint
In order to remove duplication with joining arel where constraints with
`AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And`

Closes: #11963
2013-09-13 16:37:10 +03:00
Rafael Mendonça França
defdeed2fc Merge pull request #12129 from Empact/deprecate-array-bang-delegation
Deprecate the delegation of Array bang methods in ActiveRecord::Delegation

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/relation_test.rb
2013-09-12 21:36:00 -03:00
Rafael Mendonça França
33ae757376 Merge pull request #12137 from lann/fix_association_first_last
Make CollectionAssociation first/last with integer fetch with query

Conflicts:
	activerecord/CHANGELOG.md
2013-09-12 20:53:05 -03:00
Rafael Mendonça França
e1154a694d Add CHANGELOG entry for #11698
[ci skip]
2013-09-12 20:21:59 -03:00
Rafael Mendonça França
4aa89eda06 Merge pull request #12156 from rywall/from-copy-binds
Allow Relation#from to accept other relations with bind values.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-12 20:08:00 -03:00
Rafael Mendonça França
f13b278568 Check if the SQL is not a prepared statement
When the adapter is with prepared statement disabled and the binds array
is not empty the connection adapter will try to set the binds values and
will fail. Now we are checking if the adapter has the prepared statement
disabled.

Fixes #12023
2013-09-11 20:48:50 -03:00
Rafael Mendonça França
1fa76a2f3d Merge pull request #12135 from dylanahsmith/avoid_empty_transaction
Avoid empty transaction from setting has_one association on new record.

Conflicts:
	activerecord/CHANGELOG.md
2013-09-11 18:53:52 -03:00
Dylan Thacker-Smith
a94e2db05c Avoid empty transaction from setting has_one association on new record. 2013-09-11 14:27:27 -04:00
thedarkone
5cbed2bc60 Relation#merge should not lose readonly(false) flag.
The original code ignores the `false` value because `false.blank? # => true`.
2013-09-11 14:18:31 +02:00
Lann Martin
8875e28a50 Make CollectionAssociation first/last with integer fetch with query
When first or last is called with an integer on an unloaded association,
the entire collection is loaded. This differs surprisingly from the
behavior of Relation#first/last, which translate the call into a limit
query. For large collections this can make a big difference in
performance.

Change CollectionAssociation#fetch_first_or_last_using_find? to make
this kind of call delegate to Relation.
2013-09-09 15:17:44 -06:00
Ryan Wallace
af89118ca3 Typo in Changelog. 2013-09-08 15:55:35 -07:00
Ryan Wallace
87a84d3263 Allow Relation#from to accept other relations with bind values. 2013-09-08 14:00:19 -07:00
Yves Senn
beb5ea8468 Merge pull request #11958 from jetthoughts/extract_pre_process_orders_args
Re-use order arguments pre-processing for reorder
2013-09-04 02:00:09 -07:00
Paul Nikitochkin
3f1c0c2bd0 Extracted from order processing of arguments, and use it for reorder to be consistent. 2013-09-04 11:57:39 +03:00
Ben Woosley
1a40be0211 Deprecate the delegation of Array bang methods in ActiveRecord::Delegation
The primary means of returning results for Array bang methods is to modify
the array in-place. When you call these methods on a relation, that
array is created, modified, and then thrown away. Only the secondary
return value is exposed to the caller.

Removing this delegation is a straight-forward way to reduce user error
by forcing callers to first explicitly call #to_a in order to expose
the array to be acted on by the bang method.
2013-09-04 01:32:27 -07:00
Carlos Antonio da Silva
1297d223b4 Remove not necessary AR changelog entry, fix markup [ci skip] 2013-08-30 01:01:01 -03:00
Ben Cherry
5f631d63ae Test that PostgreSQL adapter includes usec when quoting DateTime 2013-08-28 18:23:59 -07:00
Mikhail Dieterle
c2e084ac48 check class hierarchy with is_a? in PredicateBuilder.expand
add changelog entry for #11945
2013-08-27 15:47:21 +03:00
Yves Senn
27dc4fa28e PG adapter deals with negative money values formatted with parenthesis.
Closes #11899.
2013-08-26 11:14:56 +02:00
Yves Senn
9f3b089b7b write changelog entry for #11922. [ci skip] 2013-08-20 18:24:48 +02:00
Xavier Noria
2443e0d11c documents 565c367 in the CHANGELOG 2013-08-19 14:39:51 +02:00
Paul Nikitochkin
0aa95a71b0 Rescue invalid ip address exceptions on assign.
In order that set attribute should not be bang method
2013-08-14 21:04:31 +03:00
Ben Woosley
d35e900c00 Restore the use of #add_to_target for nested attribute updates on existing 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.
2013-08-12 02:37:39 -07:00
Dr.(USA) Joerg Schray
018697dece Fix interactions between :before_add callbacks and nested attributes assignment
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
2013-08-12 02:37:39 -07:00
Eric Tipton
3a21870c6f Make 'enable_extension' revertible
If 'enable_extension' is used in a migration's 'change' method, use
'disable_extension' on down migration (and vice-versa).
2013-08-10 03:25:04 -04:00
Yves Senn
5ac2341fab cast hstore values on write to be consistent with reading from the db. 2013-08-08 07:27:30 +02:00
Yves Senn
806bc2add8 Fix multidimensional PG arrays containing non-string items 2013-08-07 20:28:14 +02:00
Rafael Mendonça França
4c1c2e6501 Add CHANGELOG entry for #11767
[ci skip]
2013-08-06 09:22:39 -03:00
schneems
f036239447 Create sqlite3 directory if not present
If the `db/` directory is not present on a remote machine it will blow up in unexpected ways with error messages that do not indicate there is a missing directory:

```
SQLite3::CantOpenException: unable to open database file
```

This PR checks to see if a directory exists for the sqlite3 file and if not creates it for you.

This PR is an alternative to #11692 as suggested by @josevalim
2013-08-05 12:10:52 -04:00
Carlos Antonio da Silva
0f8fe64c4e Use assert_nil instead of testing for equality 2013-08-02 09:45:12 -03:00
Rafael Mendonça França
e73f075689 Merge pull request #11714 from jetthoughts/11706_remove_bad_override_of_xml
Removed redundant xml override from pg adapter
2013-08-02 05:41:58 -07:00
Paul Nikitochkin
4371c5c4ec Removed redundant xml override from pg adapter
Closes: #11706
2013-08-02 11:04:50 +03:00
Rajarshi Das
36aaf46372 fix the changelog typo[ci skip] 2013-08-02 12:33:35 +05:30
Rafael Mendonça França
42f01e94e2 Merge branch 'revert-order-prepending'
Conflicts:
	activerecord/CHANGELOG.md
2013-07-30 00:05:47 -03:00
Rafael Mendonça França
92c5a2244e Revert change on ActiveRecord::Relation#order method that prepends new
order on the old ones

The previous behavior added a major backward incompatibility since it
impossible to have a upgrade path without major changes on the
application code.

We are taking the most conservative path to be consistent with the idea
of having a smoother upgrade on Rails 4.

We are reverting the behavior for what was in Rails 3.x and,
if needed, we will implement a new API to prepend the order clauses in
Rails 4.1.
2013-07-29 23:18:33 -03:00
sgrif
92a603387c Add ability to specify how a class is converted to Arel predicate
This adds the ability for rails apps or gems to have granular control
over how a domain object is converted to sql. One simple use case would
be to add support for Regexp. Another simple case would be something
like the following:

    class DateRange < Struct.new(:start, :end)
      def include?(date)
        (start..end).cover?(date)
      end
    end

    class DateRangePredicate
      def call(attribute, range)
        attribute.in(range.start..range.end)
      end
    end

    ActiveRecord::PredicateBuilder.register_handler(DateRange,
      DateRangePredicate.new)

More complex cases might include taking a currency object and converting
it from EUR to USD before performing the query.

By moving the existing handlers to this format, we were also able to
nicely refactor a rather nasty method in PredicateBuilder.
2013-07-28 13:12:20 -06:00
Ben Woosley
31a43ebc10 Don't allow quote_value to be called without a column
Some adapters require column information to do their job properly.
By enforcing the provision of the column for this internal method
we ensure that those using adapters that require column information
will always get the proper behavior.
2013-07-22 04:49:18 -07:00
Ben Woosley
c083dc22dd Tidy up the "Specified column type for quote_value" changes
This includes fixing typos in changelog, removing a deprecated
mocha/setup test require, and preferring the `column_for_attribute`
accessor over direct access to the columns_hash in the new code.
2013-07-22 04:39:38 -07:00
Alfred Wong
39b5bfe239 Specified column type for quote_value
When calling quote_value the underlying connection sometimes requires
more information about the column to properly return the correct quoted
value.

I ran into this issue when using optimistic locking in JRuby and the
activerecord-jdbcmssql-adapter. In SQLSever 2000, we aren't allowed to
insert a integer into a NVARCHAR column type so we need to format it as
N'3' if we want to insert into the NVARCHAR type. Unfortuantely, without
the column type being passed the connection adapter cannot properly return
the correct quote value because it doesn't know to return N'3' or '3'.

This patch is fairly straight forward where it just passes in the column
type into the quote_value, as it already has the ability to take in the column,
so it can properly handle at the connection level.

I've added the tests required to make sure that the quote_value method
is being passed the column type so that the underlying connection can
determine how to quote the value.
2013-07-22 04:39:35 -07:00
Vipul A M
0b6c1f082f rescue from all exceptions in ConnectionManagement#call
Fixes #11497

As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does not rescue from Exception (but only from StandardError),
the Connection Pool quickly runs out of connections when multiple erroneous Requests come in right after each other.

Recueing from all exceptions and not just StandardError, fixes this behaviour.
2013-07-22 14:44:33 +05:30
Yves Senn
c212cfecb1 Revert "Merge pull request #11120 from awilliams/ar_mysql2_boolean_quoting"
This reverts commit cb1d07e43926bcec95cb8b4a663ca9889173395a, reversing
changes made to 754a373e301d2df0b12a11083405252722bc8366.
2013-07-17 09:51:22 +02:00
awilliams
41bd94b7ef Unifies mysql and mysql2 casting of booleans
Using the mysql2 adapter, boolean values were sometimes being incorrectly cast
to 't' or 'f'. This changes the cast to match the mysql adapter behavior, ie 1 and 0.
2013-07-16 12:14:09 +02:00
Yves Senn
754a373e30 change_column for PG adapter respects :array option. 2013-07-16 10:56:22 +02:00
Arun Agrawal
0d4075fb47 Remove deprecation warning from attribute_missing
for attributes that are columns.
2013-07-15 19:18:36 +02:00
Paul Nikitochkin
e0d59e6219 #4566: Remove extra decrement of transaction level
`rollback_active_record_state!` tries to restore model state on `Exception`
by invoking `restore_transaction_record_state` it decrement deep level by `1`.

After restoring it ensure that states to be cleared
and level decremented by invoking `clear_transaction_record_state`,
which cause the bug: because state already reduced in `restore_transaction_record_state`.

Removed double derement of transaction level
and removed duplicated code which clear transaction state for top level.
2013-07-14 20:35:31 +03:00
kennyj
33354aa23e Reset @column_defaults when assigning . 2013-07-14 03:02:47 +09:00
kennyj
4734e4ed31 Migration dump UUID default functions to schema.rb. Fixes #10751. 2013-07-10 02:16:27 +09:00
Rafael Mendonça França
7948d78905 Merge pull request #11306 from jetthoughts/11288_remove_extra_queries_for_belongs_to_with_touch
#11288: Removed duplicated touching

Conflicts:
	activerecord/CHANGELOG.md
2013-07-06 17:33:26 -03:00
Yves Senn
b54ef7ebde Revert "Merge pull request #11299 from arunagw/disable_implicit_join_references_removed"
`disable_implicit_join_references=` was only deprecated on `master`,
not with rails 4.0. We can remove it after 4.1

This reverts commit 3c719ead414ffd29e71efce185698af979052abb, reversing
changes made to d5c3bf9722abd5733a769c8d789de3f74dbfb92d.
2013-07-05 16:44:32 +02:00
Paul Nikitochkin
1ecc3e83b6 #11288: Removed duplicated touching
if belongs to model with touch option on touch

Closes #11288
2013-07-05 17:13:54 +03:00
Arun Agrawal
6dd7f7c04e Remove deprecated ActiveRecord::Base.disable_implicit_join_references=. 2013-07-04 19:48:42 +02:00
Yves Senn
8ee599ea86 Remove deprecated nil-passing to SchemaCache methods. 2013-07-04 10:40:52 +02:00
Yves Senn
6d554b263b Remove deprecated block filter from ActiveRecord::Migrator#migrate. 2013-07-04 10:09:12 +02:00
Yves Senn
685631285f Remove deprecated String constructor from ActiveRecord::Migrator. 2013-07-04 09:49:03 +02:00
Arun Agrawal
50cbc03d18 Remove deprecated scope use without passing a callable object.
Removed tests from deprecated code.
2013-07-03 23:23:11 +02:00
Arun Agrawal
9105c59af0 Remove deprecated transaction_joinable=
in favor of `begin_transaction`
with `:joinable` option.
2013-07-03 23:23:11 +02:00
Arun Agrawal
b23501112e Remove deprecated decrement_open_transactions. 2013-07-03 23:23:11 +02:00
Arun Agrawal
51c97e7e19 removed deprecated increment_open_transactions 2013-07-03 23:23:11 +02:00
Yves Senn
fca29750e4 remove deprecated PostgreSQLAdapter#outside_transaction? method. 2013-07-03 20:49:57 +02:00
Vipul A M
28d1d3f0fb Remove deprecated ActiveRecord::Fixtures.find_table_name in favour of ActiveRecord::Fixtures.default_fixture_model_name. 2013-07-03 15:28:05 +05:30
Neeraj Singh
0e8027fb34 Removed deprecated method columns_for_remove 2013-07-03 08:21:10 +05:30
Francesco Rodriguez
341b73965d Remove deprecated SchemaStatements#distinct 2013-07-02 16:41:17 -05:00
Yves Senn
eb5b7a8ced deprecated ActiveRecord::TestCase is no longer public.
/cc @tenderlove
2013-07-02 22:12:17 +02:00
Neeraj Singh
0e3700364c Dropped deprecated option :restrict for :dependent in associations 2013-07-03 00:56:20 +05:30
Neeraj Singh
8ef2463807 Removed support for deprecated delete_sql in associations. 2013-07-03 00:10:55 +05:30
Neeraj Singh
39ee74c405 Removed support for deprecated insert_sql in associations. 2013-07-02 23:38:46 +05:30
Neeraj Singh
d80334488f Removed support for deprecated finder_sql in associations. 2013-07-02 22:08:42 +05:30
Rafael Mendonça França
f875d319ad Add CHANGELOG enty for #11235 2013-07-02 11:50:15 -03:00
Neeraj Singh
4bf1ecd6d8 Removed support for deprecated counter_sql 2013-07-02 17:54:16 +05:30
Rafael Mendonça França
260c2015b3 Merge pull request #10604 from neerajdotname/delete_all_should_not_call_callbacks
Do not invoke callbacks when delete_all is called

Conflicts:
	activerecord/CHANGELOG.md
2013-07-01 23:41:32 -03:00
Neeraj Singh
71db2420a1 calling default_scope without a proc will raise ArgumentError
Calling default_scope without a proc will now raise `ArgumentError`.
2013-07-02 08:07:33 +05:30
Neeraj Singh
cfc54e417d Removed deprecated method type_cast_code from Column 2013-07-02 07:37:51 +05:30
Neeraj Singh
a8c888cca9 Removed deprecated options for assocations
Deprecated options `delete_sql`, `insert_sql`, `finder_sql` and `counter_sql`
have been deleted.
2013-07-02 06:22:25 +05:30
Yves Senn
a444ea3478 remove deprecated ActiveRecord::Base#connection method. 2013-07-01 22:44:24 +02:00
Yves Senn
dc9ff7bb7c remove auto-explain-config deprecation warning 2013-07-01 22:18:49 +02:00
Yves Senn
2181832fca Remove deprecated :distinct option from Relation#count. 2013-07-01 22:11:20 +02:00
Neeraj Singh
1f45d3c94d Removed deprecated methods partial_updates and family
Removed deprecated methods `partial_updates`, `partial_updates?` and
`partial_updates=`
2013-07-02 00:50:50 +05:30
Rafael Mendonça França
42cf96fe9c Merge pull request #11213 from neerajdotname/scoped-deprecated
Removed deprecated scoped method

Conflicts:
	activerecord/CHANGELOG.md
2013-07-01 15:48:29 -03:00
Neeraj Singh
b343abd875 Removed deprecated method scoped 2013-07-01 23:02:08 +05:30
Neeraj Singh
432cbc8419 Removed deprecated method default_scopes? 2013-07-01 22:59:46 +05:30
Neeraj Singh
f319e4a942 Do not invoke callbacks when delete_all is called
Method `delete_all` should not be invoking callbacks and this
feature was deprecated in Rails 4.0. This is being removed.
`delete_all` will continue to honor the `:dependent` option. However
if `:dependent` value is `:destroy` then the default deletion
strategy for that collection will be applied.

User can also force a deletion strategy by passing parameter to
`delete_all`. For example you can do `@post.comments.delete_all(:nullify)`
2013-06-30 14:50:18 +05:30
Yves Senn
22b3481ba2 remove deprecated implicit join references. 2013-06-29 10:50:44 +02:00
Jon Leighton
55193e449a Apply default scope when joining associations.
For example:

    class Post < ActiveRecord::Base
      default_scope -> { where published: true }
    end

    class Comment
      belongs_to :post
    end

When calling `Comment.join(:post)`, we expect to receive only
comments on published posts, since that is the default scope for
posts.

Before this change, the default scope from `Post` was not applied,
so we'd get comments on unpublished posts.
2013-06-28 11:47:00 +01:00
Łukasz Strzałkowski
3cc7223f3d Remove depreacted finders
They were deprecated in 4.0, planned to remove in 4.1
2013-06-28 00:24:11 +02:00
Carlos Antonio da Silva
96a083b51e Fix @tenderlove's name in changelog
[ci skip]
2013-06-26 00:57:19 -03:00
wangjohn
926c4b95e4 Raising an error when nil or non-hash is passed to update_attributes. 2013-06-25 20:56:58 -07:00
Carlos Antonio da Silva
dfafac9dfe Add changelog entry for database tasks removal #10853 [ci skip] 2013-06-25 20:58:43 -03:00
Carlos Antonio da Silva
840c552047 Merge pull request #10992 from Empact/find-each-enumerator
When .find_each is called without a block, return an Enumerator.
2013-06-25 20:09:17 -03:00
Carlos Antonio da Silva
755069ee4e Merge pull request #10993 from Empact/result-each-enumerator
Change Result#each to return an Enumerator when called without a block.
2013-06-25 20:07:59 -03:00
Yves Senn
aaad6b6e13 remove trailing whitespace from Active Record CHANGELOG 2013-06-25 10:12:10 +02:00
Neeraj Singh
32420bd4bc flatten merged join_values before building the joins
fixes #10669

While joining_values special treatment is given to string values.
By flattening the array it ensures that string values are detected
as strings and not arrays.
2013-06-22 08:33:03 +05:30
Neeraj Singh
82882d4162 do not load all child records for inverse case
currently `post.comments.find(Comment.first.id)` would load all
comments for the given post to set the inverse association.

This has a huge performance penalty. Because if post has 100k
records and all these 100k records would be loaded in memory
even though the comment id was supplied.

Fix is to use in-memory records only if loaded? is true. Otherwise
load the records using full sql.

Fixes #10509
2013-06-21 23:35:12 +05:30
Yves Senn
0f3aadae3b inspect for AR model classes does not initiate a new connection. 2013-06-20 07:21:04 +02:00
Yves Senn
bfc8ffa232 add forgotten CHANGELOG entry for #10884. 2013-06-19 18:28:49 +02:00
Jon Leighton
e47b6dee85 Revert "Merge pull request #10566 from neerajdotname/10509d"
This reverts commit 2b817a5e89ac0e7aeb894a40ae7151a0cf3cef16, reversing
changes made to 353a398bee68c5ea99d76ac7601de0a5fef6f4a5.

Conflicts:
	activerecord/CHANGELOG.md

Reason: the build broke
2013-06-19 14:22:02 +01:00
Neeraj Singh
6fb5f6f3d6 log the sql that is actually sent to the database
If I have a query that produces sql
`WHERE "users"."name" = 'a         b'` then in the log all the
whitespace is being squeezed. So the sql that is printed in the
log is `WHERE "users"."name" = 'a b'`.

This can be confusing. This commit fixes it by ensuring that
whitespace is not squeezed.

fixes #10982
2013-06-19 17:37:27 +05:30
Ben Woosley
25042359b3 When .find_each is called without a block, return an Enumerator.
This lets us do things like call: .find_each.with_index
2013-06-19 04:04:13 -07:00
Neeraj Singh
2b73f780ff do not load all child records for inverse case
currently `post.comments.find(Comment.first.id)` would load all
comments for the given post to set the inverse association.

This has a huge performance penalty. Because if post has 100k
records and all these 100k records would be loaded in memory
even though the comment id was supplied.

Fix is to use in-memory records only if loaded? is true. Otherwise
load the records using full sql.

Fixes #10509
2013-06-19 04:09:43 +05:30
Ben Woosley
d6cfbaea72 Change Result#each to return an Enumerator when called without a block.
As with #10992, this lets us call #with_index, etc on the results.
2013-06-18 15:34:18 -07:00
Ben Woosley
d3abc8bc3d Fix formatting of my name in the changelog, and given Aaron credit for b483a0d2a75b 2013-06-18 12:22:11 -07:00
Ben Woosley
cab2df7b26 It takes 4 spaces or some backticks to have this code displayed as code in the changelog. 2013-06-18 12:21:56 -07:00
Yves Senn
6d10d64cba fixture setup does not rely on AR::Base.configurations.
As you can also configure your database connection using `ENV["DATABASE_URL"]`,
the fixture setup can't reply on the `.configurations` Hash.

As the fixtures are only loaded when ActiveRecord is actually used
(`rails/test_help.rb`) it should be safe to drop the check for an existing configuration.
2013-06-15 14:58:38 +02:00
Yves Senn
36bc4f5a02 regression test + mysql2 adapter raises correct error if conn is closed. 2013-06-15 14:35:14 +02:00
Yves Senn
7078ec3f98 cleanup, remove trailing whitespace from AR changelog 2013-06-15 14:34:55 +02:00
Vijay Dev
41a398f859 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	guides/source/upgrading_ruby_on_rails.md
2013-06-14 01:14:56 +05:30
Aaron Patterson
b483a0d2a7 Ambiguous reflections are on :through relationships are no longer supported.
For example, you need to change this:

  class Author < ActiveRecord::Base
    has_many :posts
    has_many :taggings, :through => :posts
  end

  class Post < ActiveRecord::Base
    has_one :tagging
    has_many :taggings
  end

  class Tagging < ActiveRecord::Base
  end

To this:

  class Author < ActiveRecord::Base
    has_many :posts
    has_many :taggings, :through => :posts, :source => :tagging
  end

  class Post < ActiveRecord::Base
    has_one :tagging
    has_many :taggings
  end

  class Tagging < ActiveRecord::Base
  end
2013-06-13 09:46:42 -07:00
Prathamesh Sonpatki
aa5b627849 Fix typos in AR changelog [ci skip] 2013-06-12 15:15:52 +05:30
Yves Senn
da9b5d4a84 Remove fall back and column restrictions for count. 2013-06-09 12:53:04 +02:00
wangjohn
d6b03a3767 Getting rid of the +automatic_inverse_of: false+ option in associations in favor
of using +inverse_of: false+ option. Changing the documentation and
adding a CHANGELOG entry for the automatic inverse detection feature.
2013-06-08 10:16:51 -07:00
Adam Anderson
e4fe4973cf Fixes #10432 add_column not creating array columns in PostgreSQL
When then PostgreSQL visitor was [added](6b7fdf3bf3)
`add_column` was no longer receiving the column options directly. This
caused the options to be lost along the way.
2013-06-04 00:18:59 -04:00
Sunny Ripert
606c09b8db Consistent use of one space only after punctuation 2013-05-28 14:38:02 +02:00
Yves Senn
aff928bacf implicit_readonly is being removed in favor of calling readonly explicitly 2013-05-27 21:07:39 +02:00
Yves Senn
ef99c11475 Fix the :primary_key option for has_many associations.
When removing records from a `has_many` association it used
the `primary_key` defined on the association.

Our test suite didn't fail because on all occurences of `:primary_key`,
the specified column was available in both tables. This prevented the
code from raising an exception but it still behaved badly.

I added a test-case to prevent regressions that failed with:

```
  1) Error:
HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL
```
2013-05-23 07:38:33 +02:00
Rafael Mendonça França
30d28b1958 Add CHANGELOG entry for 99860582b2b1c0fc42bf84c52aac57b243d42678 2013-05-22 14:41:46 -03:00
Prathamesh Sonpatki
f8a3dda6ce Fxied some typos 2013-05-18 19:23:30 +05:30
kennyj
349fc90996 Also support extensions in PostgreSQL 9.1, because this has been supported since 9.1. 2013-05-15 12:46:54 +09:00
Rafael Mendonça França
8d3c67fbc4 Merge pull request #10556 from Empact/deprecate-schema-statements-distinct
Deprecate SchemaStatements#distinct, and make SchemaStatements#columns_for_distinct nodoc.
Conflicts:
	activerecord/CHANGELOG.md
2013-05-12 14:50:28 -03:00
Rafael Mendonça França
d9e8ec61a4 Improve CHANGELOG entry [ci kip] 2013-05-11 23:51:27 -03:00
Kyle Stevens
443f8dd5cd Call assume_migrated_upto_version on connection
Call assume_migrated_upto_version on connection to prevent it from first
being picked up in method_missing. In the base class, Migration,
method_missing expects the argument to be a table name, and calls
proper_table_name on the arguments before sending to connection. If
table_name_prefix or table_name_suffix is used, the schema version changes
to prefix_version_suffix, breaking `rake test:prepare`.

Fixes #10411.
2013-05-11 22:39:39 -04:00
Neeraj Singh
3e0c06d8ab read_attribute_before_type_cast should accept symbol 2013-05-11 03:12:38 -04:00
Prathamesh Sonpatki
b5429eec60 Fix Typo existant -> existent [ci skip] 2013-05-08 09:50:46 +05:30
kennyj
abf3fef1e6 Fixed a bug in when using has_many association with :inverse_of option and UUID primary key. 2013-05-08 01:24:50 +09:00
Rafael Mendonça França
17c1143af9 Improve CHANGELOG entry [ci skip] 2013-05-06 22:22:43 -03:00
Rafael Mendonça França
19d32e89af Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache

Conflicts:
	activerecord/CHANGELOG.md
2013-05-06 22:22:07 -03:00
Ben Tucker
228720ef19 Confirm a record has not already been destroyed before decrementing
counter cache

At present, calling destroy multiple times on the same record results
in the belongs_to counter cache being decremented multiple times. With
this change the record is checked for whether it is already destroyed
prior to decrementing the counter cache.
2013-05-06 21:09:14 -04:00
Zach Ohlgren
a6bc35c82c Fix bug in ActiveRecord::Sanitization#sanitize_sql_hash_for_conditions
Fixing CHANGLOG description

Remove extra line.

Remove blank lines.
2013-05-06 17:03:18 -07:00
Neeraj Singh
3771e4d511 raise IrreversibleMigration if no column given
fixes #10419

Following code should raise  IrreversibleMigration. But the code was
failing since options is an array and not a hash.

def change
  change_table :users do |t|
    t.remove_index [:name, :email]
  end
end

Fix was to check if the options is a Hash before operating on it.
2013-05-06 15:16:42 -04:00
Olek Janiszewski
534030cf83 Do not overwrite manually built records during one-to-one nested attribute 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
2013-05-03 16:18:37 +02:00
Jon Leighton
6023a50491 Merge pull request #10417 from jholton/fix_association_auto_save
autosave_association issue that occurs when table has unique index (resubmission)
2013-05-03 05:13:14 -07:00
markevich
56445c9075 rake:db:test:prepare falls back to original environment after execution. 2013-05-02 18:09:59 +03:00
Johnny Holton
483c301e0a destroys association records before saving/inserting new association records
fixes bug introduced by  #3329
These are the conditions necessary to reproduce the bug:
- For an association, autosave => true.
- An association record is being destroyed
- A new association record is being created.
- There is a unique index one of the association's fields.
- The record being created has the same value as the record being
destroyed on the indexed field.

Before, the deletion of records was postponed until after all
insertions/saves.  Therefore the new record with the identical value in
the indexed field caused a non-unique value error to be thrown at the database
level.

With this fix, the deletions happen first, before the insertions/saves.
Therefore the record with the duplicate value is gone from the database
before the new record is created, thereby avoiding the non-uniuqe value
error.
2013-05-02 03:27:06 -04:00
Godfrey Chan
54122067ac Handle aliased attributes in ActiveRecord::Relation.
When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:

With the model

  class Topic
    alias_attribute :heading, :title
  end

The call

  Topic.where(heading: 'The First Topic')

should yield the same result as

  Topic.where(title: 'The First Topic')

This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.

This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.

Github #7839

*Godfrey Chan*
2013-05-01 16:36:01 -07:00
Godfrey Chan
2496bd9a98 Mute psql output when running rake db:schema:load 2013-04-30 17:24:29 -07:00
Chris Thompson
ebd7cc6f45 Fix #8856 Ensure has_one association=(associate) triggers save.
activerecord/lib/active_record/associations.rb states:

    # [association=(associate)]
    #   Assigns the associate object, extracts the primary key, sets it as the foreign key,
    #   and saves the associate object.

Since commit 42dd5d9f2976677a4bf22347f2dde1a8135dfbb4 to fix #7191, this
is no longer the case if the associate has changed, but is the same
object. For example:

    # Pirate has_one :ship
    pirate = Pirate.create!(catchphrase: "A Pirate")
    ship = pirate.build_ship(name: 'old name')
    ship.save!

    ship.name = 'new name'
    pirate.ship = ship

That last line should trigger a save. Although we are not changing the
association, the associate (ship) has changed.
2013-04-30 16:14:16 -07:00