Commit Graph

209 Commits

Author SHA1 Message Date
Alexis Bernard
a58cafeb3a Fix find_in_batches against string IDs when start option is not specified. 2012-10-31 15:39:24 +01:00
Nikita Afanasenko
e7e59a75aa Fix attributes_before_type_cast for serialised attributes.
Public method `attributes_before_type_cast` used to return internal AR structure (ActiveRecord::AttributeMethods::Serialization::Attribute), patch fixes this. Now behaves like `read_attribute_before_type_cast` and returns unserialised values.
2012-10-31 13:16:44 +04:00
kennyj
a7c3c90250 Fix #6951. Use query cache/uncache, when using not only database.yml but also DATABASE_URL. 2012-10-31 10:04:10 +09:00
Juanjo Bazán
300d080ada ActiveRecord::Relation#none! method. 2012-10-28 22:18:45 +01:00
Henrik N
1849665f73 Enable update_column(s) for the primary key attribute.
Didn't work before because it updated the model-in-memory first, so the DB query couldn't find the record.
2012-10-28 21:28:54 +01:00
Yves Senn
e4790a2c5b raise ArgumentError when redefining the primary key column. Closes #6378 2012-10-28 20:40:37 +01:00
Francesco Rodriguez
10f6f90d9d AR::AttributeMethods#[] raises AM::AttributeMissingError for missing attributes.
This fixes the following behaviour:

    class Person < ActiveRecord::Base
      belongs_to :company
    end

    # Before:
    person = Person.select('id').first
    person[:name]       # => nil
    person.name         # => ActiveModel::MissingAttributeError: missing_attribute: name
    person[:company_id] # => nil
    person.company      # => nil

    # After:
    person = Person.select('id').first
    person[:name]       # => ActiveModel::MissingAttributeError: missing_attribute: name
    person.name         # => ActiveModel::MissingAttributeError: missing_attribute: name
    person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
    person.company      # => ActiveModel::MissingAttributeError: missing_attribute: company_id

Fixes #5433.
2012-10-28 14:18:31 -05:00
Victor Costan
5d30e44390 Use the MySQL varbinary type when appropriate in migrations. 2012-10-27 13:41:27 -04:00
Shawn Veader
f96b410bc7 Decode attributes pulled from URI.parse
The RFC indicates that username and passwords may be encoded.
http://tools.ietf.org/html/rfc2396#section-3.2.2

Found this trying to use the mysql://username:password@host:port/db and having special characters in the password which needed to be URI encoded.
2012-10-26 15:43:07 -04:00
Jon Leighton
9e4c41c903 Remove ActiveRecord::Model
In the end I think the pain of implementing this seamlessly was not
worth the gain provided.

The intention was that it would allow plain ruby objects that might not
live in your main application to be subclassed and have persistence
mixed in. But I've decided that the benefit of doing that is not worth
the amount of complexity that the implementation introduced.
2012-10-26 15:51:02 +01:00
Uģis Ozols
1a6b082808 Fix incorrect markdown by removing extra space. 2012-10-24 16:15:48 +03:00
Jeremy Kemper
4ed156336f Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."
This reverts commit 83846838252397b3781eed165ca301e05db39293.
2012-10-20 11:35:16 -07:00
Jon Leighton
8384683825 Get rid of the ActiveRecord::Model::DeprecationProxy thing.
I think it's going to be too much pain to try to transition the
:active_record load hook from executing against Base to executing
against Model.

For example, after Model is included in Base, and modules included in
Model will no longer get added to the ancestors of Base.

So plugins which wish to be compatible with both Model and Base should
use the :active_record_model load hook which executes *before* Base gets
loaded.

In general, ActiveRecord::Model is an advanced feature at the moment and
probably most people will continue to inherit from ActiveRecord::Base
for the time being.
2012-10-19 18:12:54 +01:00
Jon Leighton
7efb1feaa3 Rename the partial_updates config to partial_writes
This reflects the fact that it now impact inserts as well as updates.
2012-10-19 16:45:41 +01:00
Jon Leighton
0096f53b25 nodoc the first_or_create methods and document alternatives 2012-10-19 15:56:18 +01:00
Jon Leighton
eb72e62c30 Add Relation#find_or_create_by and friends
This is similar to #first_or_create, but slightly different and a nicer
API. See the CHANGELOG/docs in the commit.

Fixes #7853
2012-10-19 13:18:47 +01:00
Scott Willson
25262bc280 Fix bug with presence validation of associations.
Would incorrectly add duplicated errors when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
2012-10-16 19:04:40 -07:00
Santiago Pastorino
c432c74cd3 Merge pull request #7371 from csmuc/fix_dup_validation_errors
Dup'ed ActiveRecord objects may not share the errors object
2012-10-16 09:46:44 -07:00
Christian Seiler
fb66521772 Call super to nullify the reference to the original errors object in the dup'ed object (call ActiveModel::Validations#initialize_dup). Closes #7291 2012-10-16 15:09:23 +02:00
Carlos Antonio da Silva
d207a33e00 Move changelog entry from #7439 to the top [ci skip] 2012-10-15 19:19:34 -03:00
Tim Macfarlane
51d6e21c96 ActiveRecord: sum expression returns string '0' for no records, fixed 2012-10-15 22:31:05 +01:00
Arturo Pie
54b3f41741 #7914 Add change of previous commit to CHANGELOG.md 2012-10-13 22:18:50 -04:00
Tima Maslyuchenko
633ea6a826 learn ActiveRecord::QueryMethods#order work with hash arguments 2012-10-12 17:57:24 +03:00
Alexey Muranov
bf4d6a2353 Add CHANGELOG entry for "Fixtures" -> "FixtureSet" 2012-10-07 20:43:18 +02:00
Yves Senn
16e4a53b78 PostgreSQL, quote table names when fetching the primary key. Closes #5920 2012-10-05 08:54:38 +02:00
Rafael Mendonça França
d7d228402e Fix CHANGELOG entry [ci skip] 2012-10-04 10:23:27 -03:00
Francesco Rodriguez
aa202adf6c Count returns 0 without querying if parent is not saved
Patches `CollectionAssociation#count` to return 0 without querying
if the parent record is new. Consider the following code:

    class Account
      has_many :dossiers
    end

    class Dossier
      belongs_to :account
    end

    a = Account.new
    a.dossiers.build

    # before patch
    a.dossiers.count
    # SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL
    # => 0

    # after
    a.dosiers.count # fires without sql query
    # => 0

Fixes #1856.
2012-10-03 18:02:14 -05:00
lulalala
6e56a03f83 Fix reset_counters() crashing on has_many :through associations.
The counter column name in the intermediate model need to be access
via the through reflection.
2012-10-02 23:49:32 +08:00
Rafael Mendonça França
77fbe1c019 Add missing CHANGELOG entry removed by mistake at 7f3b475 [ci skip] 2012-09-28 14:12:17 -03:00
Jon Leighton
144e8691cb Support for partial inserts.
When inserting new records, only the fields which have been changed
from the defaults will actually be included in the INSERT statement.
The other fields will be populated by the database.

This is more efficient, and also means that it will be safe to
remove database columns without getting subsequent errors in running
app processes (so long as the code in those processes doesn't
contain any references to the removed column).
2012-09-28 18:08:14 +01:00
Sebastian Martinez
bca66a3547 Add #update_columns entry to AR Changelog. 2012-09-28 13:58:07 -03:00
John Foley
f31ea4df3a Add CHANGELOG entry and update the guide 2012-09-23 12:57:19 -06:00
Santiago Pastorino
eb876c4d07 Revert "Fix find_in_batches with customized primary_key"
This reverts commit 761bc751d31c22e2c2fdae2b4cdd435b68b6d783.

This commit wasn't fixing any issue just using the same table for
different models with different primary keys.
2012-09-21 19:14:17 -03:00
Jon Leighton
392eeecc11 Support for specifying transaction isolation level
If your database supports setting the isolation level for a transaction,
you can set it like so:

  Post.transaction(isolation: :serializable) do
    # ...
  end

Valid isolation levels are:

* `:read_uncommitted`
* `:read_committed`
* `:repeatable_read`
* `:serializable`

You should consult the documentation for your database to understand the
semantics of these different levels:

* http://www.postgresql.org/docs/9.1/static/transaction-iso.html
* https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html

An `ActiveRecord::TransactionIsolationError` will be raised if:

* The adapter does not support setting the isolation level
* You are joining an existing open transaction
* You are creating a nested (savepoint) transaction

The mysql, mysql2 and postgresql adapters support setting the
transaction isolation level. However, support is disabled for mysql
versions below 5, because they are affected by a bug
(http://bugs.mysql.com/bug.php?id=39170) which means the isolation level
gets persisted outside the transaction.
2012-09-21 16:32:27 +01:00
Francesco Rodriguez
f4a9d7db1c remove unnecessary entry and make minor edits to AR/CHANGELOG [ci skip] 2012-09-20 13:48:32 -05:00
Francesco Rodriguez
a30b8d38b4 rename AR::Model::Tag to AR::Tag - fixes #7714 2012-09-20 12:43:12 -05:00
Guillermo Iguaran
1f4c89fbde Update changelogs to add entries about strong_parameters integration 2012-09-19 17:50:39 -05:00
Rafael Mendonça França
69e0e3f91b Improve the CHANGELOG entry for #6971 2012-09-19 12:09:36 -03:00
Damien Mathieu
30a576fa14 fix querying with an empty hash
Closes #6960
2012-09-19 15:57:22 +02:00
Xavier Noria
254a3249d8 ActiveRecord -> Active Record 2012-09-18 10:51:27 +02:00
Rafael Mendonça França
c35a7d78ec Use the CHANGELOG convention [ci skip] 2012-09-17 10:49:28 -03:00
Rafael Mendonça França
82d507b4c3 Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmt
Fix collection= on hm:t join models when unsaved
2012-09-17 06:40:38 -07:00
Ernie Miller
610b63288f Fix collection= on hm:t join models when unsaved
If assigning to a has_many :through collection against an unsaved
object using the collection=[<array_of_items>] syntax, the join models
were not properly created, previously.
2012-09-17 09:20:18 -04:00
Francesco Rodriguez
0aaf87c1e1 improve AR/CHANGELOG [ci skip] 2012-09-16 22:34:43 -05:00
Rafael Mendonça França
beaac33f9f Merge pull request #7547 from danmcclain/pg-arrays
Adds migration and type casting support for PostgreSQL Array datatype
2012-09-16 20:07:28 -07:00
kennyj
5bb056d268 Don't explain except normal CRUD sql. 2012-09-17 00:22:34 +09:00
Toshiyuki Kawanishi
761bc751d3 Fix find_in_batches with customized primary_key 2012-09-16 20:02:23 +09:00
Dan McClain
4544d2bc90 Moves column dump specific code to a module included in AbstractAdapter
Having column related schema dumper code in the AbstractAdapter. The
code remains the same, but by placing it in the AbstractAdapter, we can
then overwrite it with Adapter specific methods that will help with
Adapter specific data types.

The goal of moving this code here is to create a new migration key for
PostgreSQL's array type. Since any datatype can be an array, the goal is
to have ':array => true' as a migration option, turning the datatype
into an array. I've implemented this in postgres_ext, the syntax is
shown here: https://github.com/dockyard/postgres_ext#arrays

Adds array migration support

Adds array_test.rb outlining the test cases for array data type
Adds pg_array_parser to Gemfile for testing
Adds pg_array_parser to postgresql_adapter (unused in this commit)

Adds schema dump support for arrays

Adds postgres array type casting support

Updates changelog, adds note for inet and cidr support, which I forgot to add before

Removing debugger, Adds pg_array_parser to JRuby platform

Removes pg_array_parser requirement, creates ArrayParser module used by
PostgreSQLAdapter
2012-09-14 08:43:47 -04:00
Matt Jones
46873aeded refactor store_accessor 2012-09-13 10:12:11 -04:00
beerlington
3da275c439 Accept belongs_to assoc. keys in ActiveRecord queries
Allows you to specify the model association key in a belongs_to
relationship instead of the foreign key.

The following queries are now equivalent:

Post.where(:author_id => Author.first)
Post.where(:author => Author.first)

PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure)
PriceEstimate.where(:estimate_of => treasure)
2012-09-11 14:11:51 -04:00