Commit Graph

1061 Commits

Author SHA1 Message Date
Rafael Mendonça França
7042fe2f84 Deprecate passing a string as third argument of add_index
This was there due historical reasons since
7dc45818dc43c163700efc9896a0f3feafa31138 to give the user the
possibility to create unique indexes passing "UNIQUE" as the third
argument
2012-11-02 20:03:26 -02:00
Rafael Mendonça França
8fc52706c3 Raise an ArgumentError when passing an invalid option to add_index
Closes #8104
2012-11-02 19:00:58 -02:00
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
kennyj
ccc6910cb0 Use native mysqldump command for 'rake db:structure:dump'. 2012-09-12 02:17:04 +09:00
Ernie Miller
4f107da4ff Raise MissingAttributeError on query methods
When calling a query method on an attribute that was not selected by
an ActiveRecord query, an ActiveModel::MissingAttributeError is not
raised. Instead, a nil value is returned, which will return false once
cast to boolean.

This is undesirable, as we should not give the impression that we know
the attribute's boolean value when we haven't loaded the attribute's
(possibly) non-boolean value from the database.

This issue is present on versions going back as far as 2.3, at least.
2012-09-08 17:40:01 -04:00
Francesco Rodriguez
65ce6fb0a7 improve AR CHANGELOG [ci skip] 2012-09-08 11:34:22 -05:00
Carlos Antonio da Silva
aaa33e6f49 Improve latest AR and AP changelog entries 2012-09-08 09:07:07 -03:00
Konstantin Shabanov
b485b8a066 Dump schema using new style hash 2012-09-08 11:09:49 +04:00
Carlos Antonio da Silva
f415475621 Add changelog entry for #7545: map interval with precision to string
Merged in f41dba27a411fe3e2ddeb8d9ab6856dbb23acd02
[ci skip]
2012-09-07 15:27:50 -03:00
Carlos Antonio da Silva
ae516f6535 Remove 3.2.x entries from Active Record changelog [ci skip]
Since 810a50dacf9ddddc1d59c1cb350e8ce785c8bf85, the new policy is to
keep old changelogs in their own branches, to avoid manual syncing
across different branches.

Please check that commit for more reasoning about the new policy.
2012-09-07 11:12:10 -03:00
Carlos Antonio da Silva
d8fbfee81e Add Changelog entry for #4976: fix eager load associations without pks [ci skip] 2012-09-07 11:12:06 -03:00
Prem Sichanugrist
db8460ca0f Update Active Record CHANGELOG for #7419 2012-09-06 16:19:47 -04:00
Dickson S. Guedes
3b516b5beb ActiveRecord support to PostgreSQL 9.2 JSON type
This implements the support to encode/decode JSON
data to/from database and creating columns of type
JSON using a native type [1] supported by PostgreSQL
from version 9.2.

[1] http://www.postgresql.org/docs/9.2/static/datatype-json.html
2012-09-05 22:39:43 -03:00
Rafael Mendonça França
ddaeaefc2a Add CHANGELOG entry for #7532 [ci skip] 2012-09-05 19:38:54 -03:00
Ian Lesperance
c7d752fe2f Fix pluck when columns/tables are reserved words. 2012-09-05 18:00:07 -04:00
Adam Meehan
acf583a5e0 Update changelog with time column type casting fix 2012-09-05 21:05:25 +10:00
Xavier Noria
810a50dacf CHANGELOGs are now per branch
Changes in old branches needed to be manually synched in CHANGELOGs of newer ones.
This has proven to be brittle, sometimes one just forgets this manual step.
With this commit we switch to CHANGELOGs per branch. When a new major version is
cut from master, the CHANGELOGs in master start being blank.

A link to the CHANGELOG of the previous branch allows anyone interested to
follow the history.
2012-08-28 21:15:16 +02:00
Rafael Mendonça França
e6e5898b5a Remove CHANGELOG entry for the update_attribute removal.
We reverted the removal because the new deprecation policy
2012-08-26 01:18:37 -03:00
Mikhail Dieterle
ff8f759405 changelog #7449 2012-08-26 03:42:40 +03:00
Prem Sichanugrist
0ffe19056c Extract ActiveRecord::SessionStore from Rails
This functionality will be available from gem
`active_record-session_store` instead.
2012-08-24 15:24:19 -04:00
Dave Desrochers
ff0d9b93b9 reset_counters() was crashing when there were multiple belongs_to associations with the same foreign key.
This closes #5200.
2012-08-21 14:10:11 -03:00
kennyj
57bef99073 Use instance_accessor: false instead of instance_writer. 2012-08-21 23:40:28 +09:00
Rafael Mendonça França
55d943c567 Add CHANGELOG entry for #6986 2012-08-21 10:18:10 -03:00
brainopia
c9c5566ace Use inversed parent for first and last child of has_many association 2012-08-18 18:11:28 +04:00
Rafael Mendonça França
8f4ee48687 Merge pull request #7352 from aripollak/microsecond-timestamp
Fix occasional microsecond conversion inaccuracy
2012-08-17 10:19:33 -07:00
Jon Leighton
17bb324f38 Renaming active_record_deprecated_finders to activerecord-deprecated_finders
For consistency with the other AR extension plugins we are creating.
2012-08-17 10:21:52 +01:00
Ari Pollak
53ca22f2e1 Fix occasional microsecond conversion inaccuracy
ActiveRecord::ConnectionAdapters::Column#microseconds did an unnecessary
conversion to from Rational to float when calculating the integer number
of microseconds. Some terminating decimal numbers in base10 are
repeating decimal numbers in base2 (the format of float), and
occasionally this causes a rounding error.
Patch & explanation originally from Logan Bowers.
2012-08-15 13:21:57 -04:00
Carlos Antonio da Silva
bf5f6562c0 Remove duplicated changelog entry [ci skip] 2012-08-15 12:48:38 -03:00
Carlos Antonio da Silva
dd64f0a010 Move changelog entry to the top [ci skip] 2012-08-15 12:47:20 -03:00
Carlos Antonio da Silva
cf232e37ad Merge pull request #7133 from roshats/fix_update_all_with_blank_argument
Change Relation#update_all with blank argument to raise an ArgumentError 
instead of trying an update with empty fields.
2012-08-15 08:45:15 -07:00
Roman Shatsov
f28096476d raise ArgumentError if list of attributes to change is empty in update_all 2012-08-14 21:04:48 +03:00
Dave Yeu
a4801a792a Restore state on create when ActiveRecord::RecordInvalid is raised
This fixes issue #3217.
2012-08-11 21:54:00 -04:00
Rafael Mendonça França
8781b266b9 Sync CHANGELOGs [ci skip] 2012-08-11 13:13:58 -03:00
Wojciech Wnętrzak
21b5b6a35c Added changelog entry for table name prefix fix [ci skip] 2012-08-11 14:01:24 +02:00
Jon Leighton
5ad79989ef Remove the dependent_restrict_raises option.
It's not really a good idea to have this as a global config option. We
should allow people to specify the behaviour per association.

There will now be two new values:

* :dependent => :restrict_with_exception implements the current
  behaviour of :restrict. :restrict itself is deprecated in favour of
  :restrict_with_exception.
* :dependent => :restrict_with_error implements the new behaviour - it
  adds an error to the owner if there are dependent records present

See #4727 for the original discussion of this.
2012-08-10 17:45:06 +01:00
Rafael Mendonça França
f784f218ea Merge pull request #7140 from seamusabshere/patch-1
Make sure :environment task is executed before db:schema:load or
db:structure:load
2012-08-05 20:38:02 -03:00
Rafael Mendonça França
e7e86566cc Update changelog 2012-08-05 20:33:26 -03:00
Jon Leighton
55b24888bb Remove ActiveRecord::Base.to_a
On reflection, it seems like a bit of a weird method to have on
ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
2012-08-03 11:51:52 +01:00
Jon Leighton
0a6833b6f7 reinstate changelog that seems to have been accidentally deleted o_O 2012-08-03 11:50:50 +01:00
Jon Leighton
bf2df6e7ba Allow Relation#merge to take a proc.
This was requested by DHH to allow creating of one's own custom
association macros.

For example:

    module Commentable
      def has_many_comments(extra)
        has_many :comments, -> { where(:foo).merge(extra) }
      end
    end

    class Post < ActiveRecord::Base
      extend Commentable
      has_many_comments -> { where(:bar) }
    end
2012-08-03 11:05:31 +01:00
Jon Leighton
0e1cafcbc4 Add CollectionProxy#scope
This can be used to get a Relation from an association.

Previously we had a #scoped method, but we're deprecating that for
AR::Base, so it doesn't make sense to have it here.

This was requested by DHH, to facilitate code like this:

    Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
      @topics      = @project.topics.scope
      @todolists   = @project.todolists.scope
      @attachments = @project.attachments.scope
      @documents   = @project.documents.scope
    end
2012-08-01 23:19:52 +01:00
Jon Leighton
437851ea02 Add Relation#load
This method explicitly loads the records and then returns `self`.

Rather than deciding between "do I want an array or a relation?",
most people are actually asking themselves "do I want to eager load
or lazy load?" Therefore, this method provides a way to explicitly
eager-load without having to switch from a `Relation` to an array.

Example:

    @posts = Post.where(published: true).load
2012-08-01 21:59:46 +01:00
Jon Leighton
4efebdedf8 Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql. 2012-08-01 19:46:31 +01:00
Jon Leighton
7f3b475608 Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."
This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370.

Conflicts:
	activerecord/CHANGELOG.md

It will be deprecated only in 4.0, and removed properly in 4.1.
2012-08-01 19:46:31 +01:00
kennyj
79dc922087 Change AR's CHANGELOG, because it is related to e35c67ae0f920011a2440210041e96659a8de985 2012-08-02 01:44:11 +09:00
Bogdan Gusiev
92641efeec AR::Relation#order: make new order prepend old one
User.order("name asc").order("created_at desc")
    # SELECT * FROM users ORDER BY created_at desc, name asc

This also affects order defined in `default_scope` or any kind of associations.
2012-07-31 10:24:18 +03:00
Rafael Mendonça França
4ac81de52f Remove the deprecation of update_column.
update_column was suggested as replacement of update_attribute at the
last release of 3-2-stable, so deprecating it now will confuse the
users.
2012-07-30 10:50:18 -03:00
Rafael Mendonça França
f4d818d51e Revert "Removing composed_of from ActiveRecord."
This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592.

Reason: we need to discuss a better path from this removal.

Conflicts:
	activerecord/lib/active_record/reflection.rb
	activerecord/test/cases/base_test.rb
	activerecord/test/models/developer.rb
2012-07-27 19:25:14 -03:00
José Valim
1fab518c6a Merge pull request #6827 from zephyr-dev/master
Validates_presence_of associated object marked for destruction
2012-07-27 11:02:29 -07:00
Jon Leighton
3205c768b7 Changelog and doc updates for the previous changes. 2012-07-27 18:08:18 +01:00
Ayrton De Craene
c046a29a32 Update activerecord/CHANGELOG.md
Fixed markdown code indenting
2012-07-26 10:30:50 +03:00
Philip Arndt
ffe8b0a36a Switched update_column recommendation in changelog to update_columns
Related to #7164

Looks like the last one; thanks!
2012-07-26 16:01:51 +12:00
Rafael Mendonça França
2d9e5a26a1 Deprecate update_column in favor of update_columns.
Closes #1190
2012-07-24 20:20:26 -03:00
Brent Wheeldon & Nick Monje
9feda92940 AR has a subclass of AM:PresenceValidator.
This allows us to mark the parent object as invalid if all associated objects
in a presence validated association are marked for destruction.

See: https://github.com/rails/rails/issues/6812
2012-07-20 17:37:57 -04:00
Jon Leighton
3803fcce26 Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql. 2012-07-20 19:00:46 +01:00
José Valim
24705014b8 Use attributes instead of table names in migration example 2012-07-19 09:05:54 +03:00
José Valim
e243a8a32e Update changelog for migration generator change 2012-07-18 09:47:52 +02:00
Jon Leighton
90e42ff163 fixup changelog 2012-07-07 10:08:14 +01:00
Damien Mathieu
7d0053e6a7 Limit the number of records in Relation#inspect
While it's interesting to have the results array, it can make a console or a webpage freeze if there are a lot of them.
So this limits the number of records displayed in #inspect to 10 and tells how much were effectively found.
2012-07-06 20:04:38 +02:00
Carlos Antonio da Silva
48fe38201d Update release notes with AR::Relation#inspect change [ci skip]
See 07314e64fd62fb8e6165c8c539420160da9437e9.
Also fix some tabs in AR Changelog.
2012-07-06 08:57:59 -03:00
Jon Leighton
07314e64fd Show the records in Relation#inspect
The reason for removing the previous implementation of `#inspect` was
that it hid from you that you were dealing with a `Relation` rather than
an `Array`.

But it is still useful to be able to see the records, particularly if you're
writing something like the following in tests:

    assert_equal [foo], Post.where(:bar)

If the assertion fails, you want to see what records were actually
loaded.

So this implementation makes it clear that you've got a `Relation`, but
also shows your records.
2012-07-06 10:39:46 +01:00
Aleksey Magusev
17d2115e3d Add changelog entry for references statements 2012-07-03 13:25:25 -03:00
Carlos Antonio da Silva
215d41d802 Update 4.0 Release Notes with changelogs [ci skip]
Also fix some wrong formatting.

Related discussion:
ab72040b74 (commitcomment-1525256)
2012-07-02 22:34:51 -03:00
Rafael Mendonça França
aafa00f4c1 Unify the collation API for the database adpters 2012-07-01 12:58:41 -03:00
Carlos Antonio da Silva
ab72040b74 Update AR and AP changelogs [ci skip] 2012-06-30 16:31:40 -03:00
Brian Cardarella
05c7e0ae64 Remove ActiveRelation#inspect 2012-06-29 14:58:19 -05:00
kennyj
8fe458af1a Added an entry about fda24312d3 in the CHANGELOG. 2012-06-29 19:18:44 +09:00
Egor Lynko
359592bba6 exists?(false) returns false
`FinderMethods#exists?` finder method now returns *false* with the *false* argument
2012-06-25 18:30:15 +03:00
Tony Schneider
6657ec9a0a Allow precision option for postgresql datetimes
This patch addresses the difficulty of retrieving datetime fields. By default, the database holds a higher precision than the time as a String.

This issue is discussed at length at the following links:
- [#3519](https://github.com/rails/rails/issues/3519)
- [#3520](https://github.com/rails/rails/issues/3520)

Also, kudos to @mattscilipoti
2012-06-22 14:18:44 -04:00
Carlos Antonio da Silva
9298d60af0 Fix changelog typo [ci skip] 2012-06-22 09:44:30 -03:00
Carlos Antonio da Silva
e5cd300bec Add changelog entry and guide updates for pluck with multiple columns 2012-06-22 09:32:41 -03:00
Andrew White
bacfa9d1ca It's AR::Reflection not AR::Relation 2012-06-22 10:19:34 +01:00
Andrew White
46492949b8 Improve the derivation of HABTM assocation join table names
Improve the derivation of HABTM join table name to take account of nesting.
It now takes the table names of the two models, sorts them lexically and
then joins them, stripping any common prefix from the second table name.

Some examples:

  Top level models
  (Category <=> Product)
  Old: categories_products
  New: categories_products

  Top level models with a global table_name_prefix
  (Category <=> Product)
  Old: site_categories_products
  New: site_categories_products

  Nested models in a module without a table_name_prefix method
  (Admin::Category <=> Admin::Product)
  Old: categories_products
  New: categories_products

  Nested models in a module with a table_name_prefix method
  (Admin::Category <=> Admin::Product)
  Old: categories_products
  New: admin_categories_products

  Nested models in a parent model
  (Catalog::Category <=> Catalog::Product)
  Old: categories_products
  New: catalog_categories_products

  Nested models in different parent models
  (Catalog::Category <=> Content::Page)
  Old: categories_pages
  New: catalog_categories_content_pages

Also as part of this commit the validity checks for HABTM assocations have
been moved to ActiveRecord::Reflection One side effect of this is to move when
the exceptions are raised from the point of declaration to when the association
is built. This is consistant with other association validity checks.
2012-06-22 06:27:11 +01:00
Carlos Antonio da Silva
8593964d97 Refactor and use class_attribute 2012-06-18 23:54:13 -03:00
Joost Baaij
757f7231cc Remember the stored attributes in a config attribute.
This allows you to retrieve the list of attributes you've defined.
Usable for e.g. selects in the view, or interators based on the
attributes you wish to store in the serialized column.
2012-06-18 23:49:48 -03:00
Rafael Mendonça França
df2104e067 Improve the CHANGELOG entry [ci skip] 2012-06-18 23:00:08 -03:00
Rafael Mendonça França
7fe0f27e2b Add CHANGELOG entry to composed_of removal 2012-06-18 16:48:12 -03:00
kennyj
052e415f22 Change minimum (default) log level in PostgreSQL to warning. 2012-06-18 13:05:17 -03:00
Rafael Mendonça França
508834c599 Add CHANGELOG entry to the uuid datatype support to PostgreSQL adpter 2012-06-14 19:21:58 -03:00
Xavier Noria
86af7d3578 registers the removal of update_attribute in the CHANGELOG 2012-06-14 23:28:16 +02:00
Xavier Noria
f278b06789 removes item in the Active Record CHANGELOG
That change to update_attribute was considered
to be too subtle and was reverted in 30ea923
just before Rails 3 shipped. Later we introduced
update_column (Rails 3.1).
2012-06-14 11:50:10 +02:00
José Valim
03f2249153 Use . instead of :: for class methods, add CHANGELOG entries 2012-06-10 11:38:37 +02:00
Marc-Andre Lafortune
4faaa81161 + ActiveRecord::Base#destroy! 2012-06-06 13:27:51 -04:00
Rafael Mendonça França
3449b757da Sync CHANGLOG with the 3-2-stable branch 2012-06-01 11:41:30 -03:00
Carlos Antonio da Silva
c51fb02406 Fix changelog example for count method with block [ci skip]
Missed that too, thanks again @splattael.
2012-05-31 10:10:12 -03:00
Carlos Antonio da Silva
f9cb645dfc Yield only one argument instead of splatting.
Add Changelog entry. Closes #4003
2012-05-28 23:16:34 -03:00
Francesco Rodriguez
39f0698405 Add support for CollectionAssociation#delete by Fixnum or String
I found the next issue between CollectionAssociation `delete`
and `destroy`.

    class Person < ActiveRecord::Base
      has_many :pets
    end

    person.pets.destroy(1)
    # => OK, returns the destroyed object

    person.pets.destroy("2")
    # => OK, returns the destroyed object

    person.pets.delete(1)
    # => ActiveRecord::AssociationTypeMismatch

    person.pets.delete("2")
    # => ActiveRecord::AssociationTypeMismatch

Adding support for deleting with a fixnum or string like
`destroy` method.
2012-05-28 19:57:43 -05:00
Jon Leighton
1ae68ea35f fix typo [ci skip] 2012-05-18 16:39:37 +01:00
Jon Leighton
103ce300ec add changelogs about deprecated stuff [ci skip] 2012-05-18 16:30:05 +01:00
Johannes Barre
a8b370f5c2 Don't destroy readonly models 2012-05-17 17:52:17 +02:00
Radoslav Stankov
64872d1e34 Relation#from to accept other Relation objects
Record.from("(#{sub_query.to_sql})")    -> Record.from(sub_query)
Record.from("(#{sub_query.to_sql}) a")  -> Record.from(sub_query, :a)
2012-05-17 02:36:13 +03:00
Alexey Vakhov
2baa8ba953 Fix misprint in AR changelog 2012-05-16 09:06:57 +04:00
Angelo capilleri
0bbcc91b8c corrected some misspelling 2012-05-15 18:01:40 +02:00
Rafael Mendonça França
9b40f5cc36 Copy edit [ci skip] 2012-05-13 19:04:33 -03:00
Andrey Voronkov
3c0bf0435c Custom coders support for ActiveRecord::Store. JSON, YAML, Marshal can be used out of the box. 2012-05-09 19:20:14 +04:00
Michael Pearson
2054a17dd8 Changelog entry regarding mysql(2) STRICT_ALL_TABLES 2012-05-05 18:53:46 +10:00
Marcelo Silveira
66b9e4c857 Adding note about first and take to the changelog 2012-05-02 21:25:41 -03:00
Vijay Dev
5722915fa7 changelog fixes. Closes #3911 2012-05-01 19:27:36 +05:30
Michael de Silva
363888109f Update Rails 3.2.3 release date in changelogs as March 30, 2012
The release date details have been taken from
http://weblog.rubyonrails.org/2012/3/30/ann-rails-3-2-3-has-been-released/
2012-04-16 13:20:53 +03:00
Joshua Wood
ca0af8221a Automatically create indexes for references/belongs_to statements in migrations. 2012-04-14 14:18:42 -07:00
Jon Leighton
8c2c60511b Add bang versions of relation query methods.
The main reason for this is that I want to separate the code that does
the mutating from the code that does the cloning.
2012-04-12 17:57:54 +01:00
Jon Leighton
13b3c77e39 Add Relation#find_by and Relation#find_by! 2012-03-30 12:52:29 +01:00
Guillermo Iguaran
bb2e2d8cb6 CHANGELOG entry for AR#slice 2012-03-29 17:50:06 -05:00
Jon Leighton
0a12a5f816 Deprecate eager-evaluated scopes.
Don't use this:

    scope :red, where(color: 'red')
    default_scope where(color: 'red')

Use this:

    scope :red, -> { where(color: 'red') }
    default_scope { where(color: 'red') }

The former has numerous issues. It is a common newbie gotcha to do
the following:

    scope :recent, where(published_at: Time.now - 2.weeks)

Or a more subtle variant:

    scope :recent, -> { where(published_at: Time.now - 2.weeks) }
    scope :recent_red, recent.where(color: 'red')

Eager scopes are also very complex to implement within Active
Record, and there are still bugs. For example, the following does
not do what you expect:

    scope :remove_conditions, except(:where)
    where(...).remove_conditions # => still has conditions
2012-03-21 22:18:18 +00:00
Carlos Antonio da Silva
dde3058c3a Expand changelog and upgrading rails guide with IdentityMap info 2012-03-13 20:08:55 -03:00
Carlos Antonio da Silva
a8dd21d8b4 Remove IdentityMap 2012-03-13 20:08:54 -03:00
Andrew White
eee32af45e Add dynamic find_or_create_by_{attribute}! method. 2012-03-12 14:16:19 +00:00
Rafael Mendonça França
d804790634 Fix my name in the CHANGELOG to follow the convention
Also add missing entries and use the formating convention
2012-03-09 00:54:21 -03:00
Vijay Dev
8a714c4d80 fix incorrect changelog headings [ci skip].
Last commit message should not have said 'Rails 4' either
2012-03-09 02:30:49 +05:30
Vijay Dev
db6542178c changelog updates for Rails 4 [ci skip] 2012-03-09 02:22:17 +05:30
kennyj
aa9b64790b Update CHANGELOG to fix wrong extension. 2012-03-08 20:07:44 +09:00
Aaron Patterson
447ecb08ca Merge pull request #5162 from kennyj/schema_cache_dump
[Proposal] Schema cache dump
2012-03-07 16:44:50 -08:00
claudiob
05c6caf48c Add release dates to documentation
Set "March 1, 2012" as the release date for 3.2.2, 3.1.4, 3.0.12
2012-03-01 11:20:03 -08:00
kennyj
46c12172fe Add entry for schema cache dump to CHANGELOG.md. 2012-03-01 01:22:42 +09:00
Paco Guzman
152a393d4f Update changelogs with rails 3.0-stable branch info 2012-02-25 13:50:08 +01:00
Josef Šimánek
b4b2f5d8e4 Update activerecord/CHANGELOG.md 2012-02-18 18:29:48 +01:00
Marcelo Silveira
d70e0236df Added where option to add_index to support postgresql partial indices
The `add_index` method now supports a `where` option that receives a
string with the partial index criteria.

    add_index(:accounts, :code, :where => "active")

    Generates

    CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
2012-02-09 01:20:52 -02:00
Juanjo Bazán
8270e4a8ce Added none query method to return zero records.
And added NullRelation class implementing the null object pattern for the `Relation` class.
2012-01-31 19:50:09 +01:00
Manoj
336ff8a97e has_many/has_one, :dependent => :restrict, deprecation added. 2012-01-29 15:28:22 +05:30
Rafael Mendonça França
080bd83df9 Add create_join_table migration helper to create HABTM join tables 2012-01-27 15:34:53 -02:00
Matt Bridges
abb1423a8d Fixed small typo in ActveRecord/CHANGELOG.md 2012-01-26 08:51:41 -06:00
Xavier Noria
9725c0cb34 syncs 3-2-stable CHANGELOGs in master 2012-01-26 13:12:04 +01:00
claudiob
6d426b1035 Add release date of Rails 3.2.0 to documentation 2012-01-26 01:53:38 -08:00
Aaron Patterson
522c0fdb55 The primary key is always initialized in the @attributes hash to nil (unless
another value has been specified).
2012-01-25 14:42:22 -08:00
Olek Janiszewski
7afbc89c37 Add ActiveRecord::Base#with_lock
Add a `with_lock` method to ActiveRecord objects, which starts
a transaction, locks the object (pessimistically) and yields to the block.
The method takes one (optional) parameter and passes it to `lock!`.

Before:

    class Order < ActiveRecord::Base
      def cancel!
        transaction do
          lock!
          # ... cancelling logic
        end
      end
    end

After:

    class Order < ActiveRecord::Base
      def cancel!
        with_lock do
          # ... cancelling logic
        end
      end
    end
2012-01-18 23:23:41 +01:00
Jon Leighton
8c0c0838cf Make it more explicit that the feature is deprecated, not removed. 2012-01-16 21:35:21 +00:00
Jon Leighton
a2dab46cae Deprecate inferred JOINs with includes + SQL snippets.
See the CHANGELOG for details.

Fixes #950.
2012-01-16 21:32:12 +00:00
Vijay Dev
84d633a0b3 Merge pull request #4387 from Karunakar/releasenotes
Added the release dates for rails 3.1.1, rails 3.1.2, rails 3.1.3
2012-01-12 11:23:51 -08:00
Santiago Pastorino
838d30f182 Add CHANGELOG entry 2012-01-11 23:52:57 -02:00
Aaron Patterson
f82e244a80 dropping support for schema_info. 2012-01-10 10:54:10 -08:00
Karunakar (Ruby)
e634d25ac8 Added the release dates for rails 3.1.1, rails 3.1.2, rails 3.1.3 2012-01-08 23:26:46 +05:30
Aaron Patterson
6769293988 connections must be checked in at the end of a thread 2011-12-30 11:37:21 -08:00
Jon Leighton
00318e9bdf Add some doc for ActiveRecord::Model 2011-12-24 11:28:03 +00:00
Aaron Patterson
96838b5192 can create hstore records via AR API 2011-12-20 14:04:50 -06:00
Aaron Patterson
776af48acb PostgreSQL hstore types are automatically deserialized from the database. 2011-12-20 14:04:50 -06:00
Vijay Dev
10a5497f2e NullStore cache belongs in Active Support 2011-12-20 23:44:47 +05:30
Brian Durand
04d5eae4e8 Add ActiveSupport::Cache::NullStore to expose caching interface without actually caching for development and test environments. 2011-12-12 13:40:29 -06:00
Piotr Sarnacki
35a1744a45 Allow to run migrations with given scope, with SCOPE=<scope>
Scope in migrations can be defined by adding suffix in filename,
like: 01_a_migration.blog.rb. Such migration have blog scope.

Scope is automatically added while copying migrations from engine,
so if you want to revert all of the migrations from given engine,
you can just run db:migrate with SCOPE, like:

    rake db:migrate SCOPE=blog
2011-12-09 22:00:51 +01:00
Xavier Noria
de24ed9f2d removes the convenience instance version of AR::Base.silence_auto_explain
Rationale: As discussed with José and Jon, this convenience
shortcut is not clearly justified and it could let the user
thing the disabled EXPLAINs are related to the model instance
rather than being globally disabled.
2011-12-03 14:26:34 +01:00
Xavier Noria
0be5adaedf implements AR::Base(.|#)silence_auto_explain 2011-12-02 11:16:26 -08:00
Xavier Noria
0306f82e0c implements automatic EXPLAIN logging for slow queries 2011-12-02 04:35:43 -08:00
David Heinemeier Hansson
83d29a283c Revert "Added ActiveRecord::Base#last_modified to work with the new fresh_when/stale? conditional get methods from Action Pack"
Needless indirection with no added value.

This reverts commit 535853e83b9092078035a5abb2aa242fba815c05.
2011-12-01 20:45:47 +01:00
David Heinemeier Hansson
535853e83b Added ActiveRecord::Base#last_modified to work with the new fresh_when/stale? conditional get methods from Action Pack 2011-12-01 19:47:14 +01:00
Bogdan Gusiev
a382d60f6a ActiveRecord::Relation#pluck method 2011-11-30 11:03:00 +02:00
Aaron Patterson
0e2477b602 Automatic closure of connections in threads is deprecated. For example
the following code is deprecated:

Thread.new { Post.find(1) }.join

It should be changed to close the database connection at the end of
the thread:

Thread.new {
  Post.find(1)
  Post.connection.close
}.join

Only people who spawn threads in their application code need to worry
about this change.
2011-11-29 15:04:41 -08:00
Jon Leighton
f3c84dc316 Deprecate set_locking_column in favour of self.locking_column= 2011-11-29 20:13:37 +00:00
Jon Leighton
1a474cc8e4 Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
Jon Leighton
7af719e81c Deprecate set_sequence_name in favour of self.sequence_name= 2011-11-29 20:13:37 +00:00
Jon Leighton
34609d67b4 Deprecate set_inheritance_column in favour of self.inheritance_column= 2011-11-29 20:13:36 +00:00
Jon Leighton
0b72a04d0c Deprecate set_table_name in favour of self.table_name= or defining your own method. 2011-11-29 20:13:36 +00:00
Jon Leighton
2169603385 Merge pull request #3636 from joshsusser/master
association methods are now generated in modules
2011-11-29 10:09:42 -08:00
Josh Susser
10834e975a changelog & docs for GeneratedFeatureMethods 2011-11-27 14:12:46 -08:00
Jon Leighton
fec85cf10d Perf fix
If we're deleting all records in an association, don't add a IN(..)
clause to the query.

Fixes #3672.
2011-11-19 14:11:29 +00:00
Jon Leighton
2ef4947ab0 Add missing CHANGELOG entry for #3678. Closes #3678. 2011-11-19 13:34:50 +00:00
Jon Leighton
9c37416a3e Verify that #3690 has been closed by previous changes to the mysql
adapters.

These tests fail on the v3.1.2 tag.

Closes #3690.
2011-11-19 12:34:15 +00:00
Jon Leighton
da02f792fe Sync CHANGELOGs from 3-1-stable 2011-11-14 11:28:12 +00:00
Xavier Noria
e7b7b44123 implements AR::Relation#explain
This is a first implementation, EXPLAIN is highly
dependent on the database and I have made some
compromises.

On one hand, the method allows you to run the most
common EXPLAIN and that's it. If you want EXPLAIN
ANALYZE in PostgreSQL you need to do it by hand.

On the other hand, I've tried to construct a string
as close as possible to the ones built by the
respective shells. The rationale is that IMO the
user should feel at home with the output and
recognize it at first sight. Per database.

I don't know whether this implementation is going
to work well. Let's see whether people like it.
2011-11-05 18:30:19 -07:00
Jon Leighton
f575e21025 Merge pull request #3525 from kennyj/fix_3440-1
Fixed an issue id false option is ignored on mysql/mysql2 (fix #3440)
2011-11-05 10:29:18 -07:00
kennyj
fb0bf3c984 Fixed an issue id false option is ignored on mysql/mysql2 (fix #3440) 2011-11-06 02:15:47 +09:00
Jon Leighton
562583c766 Add ActiveRecord::Relation#uniq for toggling DISTINCT in the SQL query 2011-11-05 16:22:18 +00:00
Vlad Jebelev
69dcd45aea AR changes to support creating ordered (asc, desc) indexes 2011-11-04 15:45:24 -05:00
Jon Leighton
281272ad36 Convert CHANGELOGs to Markdown format.
Reasons:

 * Markdown reads well as plain text, but can also be formatted.
 * It will make it easier for people to read on the web as Github
   formats the Markdown nicely.
 * It will encourage a level of consistency when people are writing
   CHANGELOG entries.

The script used to perform the conversion is at
https://gist.github.com/1339263
2011-11-04 12:55:17 +00:00