Commit Graph

568 Commits

Author SHA1 Message Date
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