Commit Graph

655 Commits

Author SHA1 Message Date
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
kennyj
253ccbc0ac Abort a rake task when missing db/structure.sql like db:schema:load task. 2013-05-01 02:37:09 +09:00
Rafael Mendonça França
feb44b9213 rails/master is now 4.1.0.beta 2013-04-29 13:15:24 -03:00
Carlos Antonio da Silva
e691272628 Minor AR changelog review [ci skip] 2013-04-24 20:32:52 -03:00
Piotr Sarnacki
a64894dac8 Merge branch 'active-record-standalone-improvements' 2013-04-24 21:41:08 +02:00
Piotr Sarnacki
b5ae43a436 Move CHANGELOG entry for db.rake improvements to 4.0.0 2013-04-24 21:05:43 +02:00
kennyj
8c8d34fa55 Added testcase for #10067 and a CHANGELOG entry about this change. 2013-04-25 03:01:19 +09:00
Andrew White
1a30cfec2f Revert "Revert "belongs_to :touch behavior now touches old association when transitioning to new association" until a proper fix is found for #10197"
This reverts commit 7389df139a35436f00876c96d20e81ba23c93f0a.

Conflicts:
	activerecord/test/cases/timestamp_test.rb
2013-04-24 15:07:39 +01:00
Piotr Sarnacki
d1d7c86d0c Don't require having Rails.application to run database tasks 2013-04-24 15:39:08 +02:00
David Heinemeier Hansson
7389df139a Revert "belongs_to :touch behavior now touches old association when transitioning to new association" until a proper fix is found for #10197 2013-04-23 09:23:57 -07:00
Matthew Robertson
1e27f1c5d5 Update counter cache when pushing into association
This commit fixes a regression bug in which counter_cache columns
were not being updated correctly when newly created records were
being pushed into an assocation. EG:

    # this was fine
    @post.comment.create!

    # this was fine
    @comment = Comment.first
    @post.comments << @comment

    # this would not update counters
    @post.comments << Comment.create!
2013-04-21 18:34:11 -07:00
Xavier Noria
d32ef7c7a5 Rewrites a CHANGELOG entry.
The entry is basically copy & paste of the commit message, but the CHANGELOG
has a different purpose than Git history, it just communicates what is new:

* No need to explain why did the bug happen (unless it is truly relevant).

* No need to explain how was the bug fixed.

* Whether the user gives new names to columns does not really matter, use of
  select to cherry-pick a column for example also presented that behaviour.
  Non-selected attributes are the key, either because they were not included
  in the selected list, or because they were but with a different alias.

* In the case of an attribute alias, what you really want to depict is that
  respond_to? returns false for the original attribute name.
2013-04-20 09:08:52 +02:00
Prathamesh Sonpatki
42df4b573e Typo Fix in AR CHANGELOG [ci skip] 2013-04-20 08:35:00 +05:30
Neeraj Singh
66001f3606 fix respond_to? for non selected column
fixes #4208

If a query selects only a few columns and gives custom names to
those columns then respond_to? was returning true for the non
selected columns. However calling those non selected columns
raises exception.

    post = Post.select("'title' as post_title").first

In the above case when `post.body` is invoked then an exception is
raised since `body` attribute is not selected. Howevere `respond_to?`
did not behave correctly.

    pos.respond_to?(:body) #=> true

Reason was that Active Record calls `super` to pass the call to
Active Model and all the columns are defined on Active Model.

Fix is to actually check if the data returned from the db contains
the data for column in question.
2013-04-19 14:09:16 -04:00
Jon Leighton
0920d4fccb Revert "Merge pull request #10183 from jholton/fix_association_auto_save"
This reverts commit e8727d37fc49d5bf9976c3cb5c46badb92cf4ced, reversing
changes made to d098e1c24bc145e0cc14532348436e14dc46d375.

Reason: it broke the mysql build
2013-04-19 16:57:06 +01:00
Johnny Holton
9de28419b1 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-04-19 10:50:56 -04:00
Rafael Mendonça França
db1594c61c Merge pull request #10217 from mirasrael/make-migrator-run-transactional-4.0
Support transactions in Migrator.run

Conflicts:
	activerecord/CHANGELOG.md
2013-04-19 11:23:56 -03:00
bondarev
2976558bc3 Support transactions in Migrator.run 2013-04-18 18:18:59 +04:00
kennyj
01a2ac12b9 Fix #7619. 0x prefix must be added when assigning hexadecimal string into bit column in Postgresql, because solving ambiguity. 2013-04-17 00:57:53 +09:00
Prathamesh Sonpatki
34ce4935d0 Fixed typos in AR CHANGELOG 2013-04-16 07:46:49 +05:30
Yves Senn
c245437de7 use unified and clean formatting in CHANGELOGS. [ci skip] 2013-04-12 15:52:43 +02:00
Noemj
dab82332c8 Switched to new naming conventions
[ci skip]
2013-04-11 13:19:49 -03:00
Rafael Mendonça França
0235cdf5ce Merge pull request #10152 from Noemj/statement_cache
Statement cache

Conflicts:
	activerecord/CHANGELOG.md
2013-04-10 16:02:26 -03:00
Noemj
af1a4bdc56 Added statement cache 2013-04-10 21:20:58 +03:00
Jared Armstrong and Neeraj Singh
dc764fcc34 While merging relations preserve context for joins
Fixes #3002. Also see #5494.

```
class Comment < ActiveRecord::Base
  belongs_to :post
end

class Author < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :author
  has_many :comments
end
```

`Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would
fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.

It is failing because `all` is being called on relation which looks like this after all the merging:
`{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that
`Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`.

Ths solution is to build JoinAssociation when two relations with join information are being merged. And later
while building the arel use the  previously built `JoinAssociation` record in `JoinDependency#graft` to
build the right from clause.

Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it
compatible with new code base.
2013-04-10 12:19:47 -04:00
Carlos Antonio da Silva
a92814b001 Minor AR changelog improvements [ci skip] 2013-04-07 13:56:58 -03:00
Agis-
666a248b0c Deprecate ActiveRecord#Base.default_scopes?
See #10107.
2013-04-06 20:34:50 +03:00
Rafael Mendonça França
d25e0c6f6a Merge pull request #10098 from subwindow/postgres_dump_bigint_default
Correctly parse bigint defaults in PostgreSQL

Conflicts:
	activerecord/CHANGELOG.md
2013-04-05 14:42:03 -03:00
Erik Peterson
661365e7ce Correctly parse bigint defaults in PostgreSQL 2013-04-05 09:37:08 -04:00
Carlos Antonio da Silva
877dfcbb64 Move changelog to the top [ci skip] 2013-04-05 10:01:38 -03:00
Jon Leighton
685cf144a9 Merge pull request #9996 from mikz/master
Association with inverse_of does not set the parent in association building block
2013-04-05 05:57:27 -07:00
Neeraj Singh
812469943c has_many through obeys order on through association
fixes #10016
2013-04-04 15:45:13 -04:00
Carlos Antonio da Silva
1e703f5d41 Move changelog entry to the top and fix conflict [ci skip] 2013-04-03 14:05:23 -03:00
David Heinemeier Hansson
9035cfc0df Merge pull request #9141 from adamgamble/issue-9091
belongs_to :touch should touch old record when transitioning.
2013-04-03 09:56:43 -07:00
kennyj
4140d7c1f4 Add CHANGELOG entry about extracting and deprecating Firebird/Sqlserver/Oracle database tasks. 2013-04-03 01:14:07 +09:00
Michal Cichra
448381593e fix inverse_of association in block of new child
This fixes inconsistency when building children of association
which has inverse_of set properly.

When creating new association object with a block:

    parent.association.build do |child|
      child.parent.equal?(parent) # false
    end

So the block the `child.parent` did not point to the same object.
But when the object is created it points to same instance:

    child = parent.association.build
    child.parent.equal?(parent) # true
2013-04-01 15:11:07 +02:00
Carlos Antonio da Silva
e0b2271026 Minor reviews in AR changelog [ci skip] 2013-03-30 13:54:34 -03:00
Ken Mazaika
9600e0b029 Add support for FULLTEXT and SPATIAL indexes using the :type flag for MySQL. 2013-03-27 23:35:54 -04:00
Sam Saffron
b37399ab98 Make connection_handler overridable per thread 2013-03-27 04:28:28 -07:00
Rafael Mendonça França
17077639c2 Merge pull request #9928 from vipulnsward/fix_rename_auto_increment_mysql
respect auto_increment in rename_column for mysql
2013-03-26 11:55:12 -07:00
Vipul A M
437961b558 respect auto_increment in rename_column for mysql 2013-03-27 00:15:59 +05:30
Dan McClain
e199dc1a57 Adds support for concurrent indexing in PostgreSQL adapter
Adds support for algorithm option in MySQL indexes
Moves USING and algorithm options upstream

The syntax is still specific to the Adapter, so the actual executed string happens
in the corresponding adapter
2013-03-25 17:56:38 -04:00
Martin Schürrer
336b376728 Make Postgres point type correspond to ruby array with two floats inside 2013-03-25 19:29:52 +01:00
doabit
8094156728 Custom index type support with :using. 2013-03-24 05:09:54 +08:00
Rafael Mendonça França
4e363b1c0e Review some CHANGELOG entries [ci skip] 2013-03-23 15:09:53 -03:00
Prathamesh Sonpatki
d5433945be Spelling 'PostgreSQL' correctly 2013-03-23 20:54:11 +05:30
Prathamesh Sonpatki
14ce0c6eea Fixed typos in activerecord CHANGELOG 2013-03-23 16:23:58 +05:30
Dmitry Vorotilin
89828a4052 When we pass id to update_attributes it will try to set new id for that record 2013-03-22 17:57:34 +04:00
Ian Young
66679c8ecd Update other counter caches on destroy 2013-03-20 13:43:07 -07:00
Vijay Dev
c81dc8e373 Merge pull request #9821 from vipulnsward/fix_typos_in_AR
Fix some typos in AR- CHANGELOG, tests, method doc. fixed
2013-03-20 01:11:57 -07:00
Rajeev N Bharshetty
b0f727880a Fix a typo 2013-03-20 13:37:02 +05:30
Vipul A M
abd89f96cd Fix some typos in AR- CHANGELOG, tests, method doc. fixed 2013-03-20 11:17:01 +05:30
wangjohn
840ca09a11 Calling find() on an association with an inverse will now check to see
if the association already holds that record in memory before checking
the database for the specified ids.
2013-03-19 16:33:49 -04:00
Yves Senn
274e966a6a rake db:create does not change permissions of root user.
Closes #8079.

I had to rework some of the tests because the mock allowed any arguments
for `connection.exeucte`. I think this is very dangerous as there could
anything be executed without the tests noticing it.
2013-03-17 20:34:04 +01:00
Xavier Noria
8744632fb5 sets limit 191 for schema_migrations#version in mysql2 if the encoding is "utf8mb4"
Please, see rationale in the included CHANGELOG patch.
2013-03-17 20:29:58 +01:00
Xavier Noria
9a421aaa82 fixes markup of the CHANGELOG entry from 455d710 2013-03-16 12:00:50 +01:00
John Wang
455d710242 If a counter_cache is defined, then using update_attributes and changing
the primary key on an association will make sure that the corresponding
counter on the association is changed properly. Fixes #9722.
2013-03-15 21:28:28 -04:00
Yves Senn
34402c7623 make it possible to disable implicit join references.
Closes #9712.
2013-03-15 16:07:05 +01:00
Yves Senn
cd87c85ef0 Deprecate the :distinct option for Relation#count.
We moved more and more away from passing options to finder / calculation
methods. The `:distinct` option in `#count` was one of the remaining places.
Since we can now combine `Relation#distinct` with `Relation#count` the option
is no longer necessary and can be deprecated.
2013-03-15 14:15:47 +01:00
Yves Senn
a1bb6c8b06 rename Relation#uniq to Relation#distinct. #uniq still works.
The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our
Relation API is close to SQL terms I renamed `#uniq` to `#distinct`.

There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue
to work. I also updated the documentation to promote the use of `#distinct`.
2013-03-15 14:15:47 +01:00
Adam Gamble
8fccbc1ad4 Modifies belong_to touch callback to touch old associations also #9091 2013-03-14 12:46:50 -05:00
Yves Senn
5ed4696b67 fix typo in Active Record CHANGELOG [ci skip] 2013-03-13 09:11:48 +01:00
Matthew M. Boedicker
d3e5118e7d Pass column to quote when copying a sqlite table.
To make quote escape binary data correctly it needs the column passed in.
2013-03-11 23:14:46 -07:00
Xavier Noria
cae93be0ca promotes change_column_null to the migrations API 2013-03-11 23:13:12 +01:00
Carlos Antonio da Silva
bbc87dbc81 Merge pull request #9633 from senny/5321_make_it_lazy
Uniqueness validation uses a proc to specify the `:conditions` option.

This is a follow up to #5321 and follows the general direction in
AR to make things lazy evaluated.
2013-03-09 14:11:21 -08:00
Yves Senn
ad1a24f0e0 Uniqueness validation uses a proc to specify the :conditions option.
This is a follow up to #5321 and follows the general direction in
AR to make things lazy evaluated.
2013-03-09 23:09:00 +01:00
Carlos Antonio da Silva
a6bd507ece Fix "ActiveRecord" => "Active Record" in changelog [ci skip] 2013-03-09 18:22:47 -03:00
Ben Moss
992d87db02 Deprecate #connection in favour of accessing it via the class
This allows end-users to have a `connection` method on their models
without clashing with ActiveRecord internals.
2013-03-09 15:16:15 -05:00
Yves Senn
a58e660837 Use "Fixes" in place of "Fix" in changelogs for consistency [ci skip]. 2013-03-09 20:57:17 +01:00
OZAWA Sakuro
c3a26c592c Preserve magic comments and content encoding of copied migrations.
During insertion of "# This migration comes from ... " comment at the beginning of
a migration, presence of magic comment was not considered.
2013-03-09 15:38:02 +09:00
Carlos Antonio da Silva
a2d57fd6b9 Fix changelog indent, remove self from method call in changelog/doc examples
[ci skip]
2013-03-08 12:35:45 -03:00
Rafael Mendonça França
74d24ea1fe Merge pull request #9497 from route/subclass_from_attrs
Fix ActiveRecord `subclass_from_attrs` when eager_load is false.

Conflicts:
	activerecord/CHANGELOG.md
2013-03-08 11:59:29 -03:00
Rafael Mendonça França
ba6b3c165f Merge pull request #8868 from tehgeekmeister/master
Use the index name explicitly provided in a migration when reverting.

Fixes #8868

Conflicts:
	activerecord/CHANGELOG.md
2013-03-08 10:35:16 -03:00
Rafael Mendonça França
22f31214a0 Merge pull request #8966 from cfabianski/disable_prepared_statement_when_preparing_a_query
Unprepared Visitor + unprepared_statement

Conflicts:
	activerecord/CHANGELOG.md
2013-03-08 10:19:58 -03:00
Jon Leighton
9f007d7fe5 Write a more comprehensive CHANGELOG message [ci skip] 2013-03-08 10:44:42 +00:00
Cédric FABIANSKI
9f549212c3 Unprepared Visitor + unprepared_statement 2013-03-08 09:14:31 +01:00
Ezekiel Smithburg
b6226c3cfb If an index can't be found by column, use the index name.
schema_statements uses the column name by default to construct the index name, and then raises an exception if it doesn't exist, even if the name option is specified, which causes #8858.  this commit makes index_name_for_remove fall back to constructing the index name to remove based on the name option.
2013-03-07 20:03:17 -08:00
Neeraj Singh and John Leighton
cd26b6ae7c Combine scope conditions using AND
Currently Post.active.inactive will result in Post.inactive since
the last where clause wins when scopes are merged.

This pull request will merge all scopes ( barring defaul scope)
using AND.

The default scope will be overridden if another scope acts on the
same where clause.

closes #7365
2013-03-07 18:57:27 -05:00
Rafael Mendonça França
2e3e171e31 Merge pull request #9105 from bemurphy/cache_key_updated_on
cache_key consults updated_on timestamp if present

Conflicts:
	activerecord/CHANGELOG.md
2013-03-07 13:28:46 -03:00
Rafael Mendonça França
d3adfd6d3b Merge pull request #9474 from HonoreDB/master
More helpful error message when instantiating an abstract class

Conflicts:
	activerecord/CHANGELOG.md
2013-03-07 13:26:03 -03:00
Yves Senn
0a5fdcd5ae rake db:structure:dump warns when mysqldump is not in PATH.
Closes #9518.

The rake task used to fail silently and left an empty `structure.sql`.
It's confusing for users to get to the root of the problem.
The warning message tells them where to look.
2013-03-06 15:12:48 +01:00
Yves Senn
854b74242c Connection#structure_dump is no longer used. #9518
As of ccc6910c we use `mysqldump` to create the `structure.sql`.
The old `#structure_dump` code is still in AR but never used.

I removed all relevant parts from the code-base.
2013-03-06 15:12:20 +01:00
Dmitry Vorotilin
b04051d4e0 Fix ActiveRecord subclass_from_attrs when eager_load is false.
It cannot find subclass because all classes are loaded automatically
when it needs.
2013-03-06 11:46:07 +04:00
Yves Senn
b337390889 transactions can be turned off per Migration.
Closes #9483.

There are SQL Queries that can't run inside a transaction. Since
the Migrator used to wrap all Migrations inside a transaction there
was no way to run these queries within a migration.

This patch adds `self.disable_ddl_transaction!` to the migration to
turn transactions off when necessary.
2013-03-05 16:12:08 +01:00
Yves Senn
4b7a33e142 assigning '0.0' to a nullable numeric column does not make it dirty 2013-03-05 14:00:41 +01:00
Dimko
71e4dfc9f4 Fixed typo in active record's changelog 2013-03-04 18:56:46 +04:00
Carlos Antonio da Silva
96050e1d73 Use 1.9 hash style in changelog and doc examples [ci skip] 2013-03-04 09:04:48 -03:00
wangjohn
293875457b Created an unscope method for removing relations from a chain of
relations. Specific where values can be unscoped, and the unscope method
still works when relations are merged or combined.
2013-03-03 20:42:01 -05:00
Aaron Weiner
53f18f2c54 More helpful error message when instantiating an abstract class
Calling a literal ActiveRecord::Base.new raises NoMethodError,
since it ends up calling Class.abstract_class? which does not exist.
Similarly, instantiating an actual abstract class hits the database,
when conventionally it should immediately throw NotImplementedError.

ActiveRecord::Base can't be made abstract without breaking many,
many things, so check for it separately.
2013-03-03 12:36:51 -05:00
Andrew White
c09f934dcb Merge pull request #9431 from troyk/patch-2
Fix PostgreSQL TIMESTAMP WITH TIME ZONE to return ActiveSupport::Time
2013-03-02 10:03:04 +00:00
Yves Senn
b9399c470b deal with #append and #prepend on association collections.
Closes #7364.

Collection associations behave similar to Arrays. However there is no
way to prepend records. And to append one should use `<<`. Before this
patch `#append` and `#prepend` did not add the record to the loaded
association.

`#append` now behaves like `<<` and `#prepend` is not defined.
2013-03-01 21:29:46 +01:00
Troy Kruthoff
2cc09441c2 Fix PostgreSQL TIMESTAMP WITH TIME ZONE to return ActiveSupport::Time
In an AR model a timestamptz attribute would return a ruby string and AR
tests did not check for any type casting.  Previous tests would pass
only because an assert_equal was being used on a Time.utc object, which
will parse the right side of the eq to a valid Time instance for
comparision.

switch to test instance of Time instead of ActiveSupport::TimeWithZone
2013-03-01 09:51:23 -08:00
Sammy Larbi
20e041579f Support creating a table migration generator
Sometimes you want to create a table without an associated model and
test, which is also not a join table. With this commit, you can now
do that.

Example:

    rails g migration create_posts title:string
or
    rails g migration CreatePosts title:string

This commit also moves the template the model generator uses for the
migration to the migration templates folder, as it seems a more
sensible place for it now that it is shared code.
2013-03-01 06:13:30 -06:00
Rafael Mendonça França
2c3362829f Improve the CHANGELOG entry
[ci skip]
2013-02-28 18:35:07 -03:00
kennyj
e2a4b7a506 Wrong exception is occured when raising no translatable exception 2013-03-01 02:47:57 +09:00
Yves Senn
5d0ca74622 Support PostgreSQL specific column types when using change_table.
Closes #9480.

We use `TableDefinition` for `#create_table` and `Table` for `#change_table`.
The PostgreSQL sepcifc types were only defined on `TableDefinition` so I
also added them to `Table`.
2013-02-28 13:42:30 +01:00
Steve Klabnik
afd4a14332 Revert "Merge pull request #9207 from dylanahsmith/mysql-quote-numeric"
This reverts commit 408227d9c5ed7de26310d72a1a99c1ee02311c63, reversing
changes made to dca0b57d03deffc933763482e615c3cf0b9a1d97.
2013-02-27 08:46:40 -08:00
Carlos Antonio da Silva
02037c3ea0 Merge pull request #9218 from Fivell/master
Fix calculation of db_runtime property in
ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime.

Previously, after raising ActionView::MissingTemplate, db_runtime was
not populated.

Closes #9218, Fixes #9215.

Conflicts:
	activerecord/CHANGELOG.md
2013-02-27 11:47:24 -03:00
Igor
dd0bbd2ccb fix db_runtime attribute value after raising ActionView::MissingTemplate exception 2013-02-27 16:35:22 +02:00
Olek Janiszewski
dce4383319 Fix touching an invalid parent record for belongs_to
If the parent of a `belongs_to` record fails to be saved due to
validation errors, `touch` will be called on a new record, which causes
an exception (see https://github.com/rails/rails/pull/9320).

Example:

    class Owner < ActiveRecord::Base
      validates_presence_of :name
    end

    class Pet < ActiveRecord::Base
      belongs_to :owner, touch: true
    end

    pet = Pet.new(owner: Owner.new)

    # Before, this line would raise ActiveRecord::ActiveRecordError
    # "can not touch on a new record object"
    pet.save
2013-02-26 18:46:10 +01:00
Rafael Mendonça França
0f75e2c51f Update CHANGELOGS 2013-02-26 13:45:57 -03:00
Rafael Mendonça França
8bc5e714f4 Merge pull request #9414 from senny/9275_order_with_symbol_and_join
Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
2013-02-26 05:15:14 -08:00
Brendon Murphy
1dc98c143c cache_key consults updated_on timestamp if present
- Extract max timestamp retrieval for cache_key
- Update changelog for cache_key changes
2013-02-26 00:04:05 -08:00
Xavier Noria
25f90a4140 typo 2013-02-25 21:31:54 +01:00
Xavier Noria
3d303f5af8 AR loads activerecord-deprecated_finders, no need to add it to the Gemfile 2013-02-25 21:31:03 +01:00
Yves Senn
e035699085 Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
Fixes #9275.

When `#order` is called with a Symbol this patch will prepend the quoted_table_name.
Before the postgresql adapter failed to build queries containg a join and an order
with a symbol.

This expansion happens for all adapters.
2013-02-25 18:00:34 +01:00
Rafael Mendonça França
d10056087c New CHANGELOG entries always on top [ci skip] 2013-02-25 12:57:19 -03:00
Hiroshige Umino
ec9aa3ca89 Do not override attributes on dup by default scopes 2013-02-26 00:30:49 +09:00
David Heinemeier Hansson
c0bc9ce38c Preparing for 4.0.0.beta1 release 2013-02-25 08:31:50 -06:00
Yves Senn
536b3f0fb5 some minor AR changelog modifications [ci skip] 2013-02-25 11:46:05 +01:00
wangjohn
e52ff80960 Raising an ActiveRecordError when one tries to use .touch(name) on a new
object that has not yet been persisted. This behavior follows the
precedent set by update_columns.
2013-02-25 00:29:28 -05:00
Carlos Antonio da Silva
0bc301ef7d Improve AR changelog [ci skip] 2013-02-24 19:33:18 -03:00
Yves Senn
4ef75b63db don't apply invalid ordering when preloading hmt associations.
closes #8663.

When preloading a hmt association there two possible scenarios:

1.) preload with 2 queries: first hm association, then hmt with id IN ()
2.) preload with join: hmt association is loaded with a join on the hm association

The bug was happening in scenario 1.) with a normal order clause on the hmt association.
The ordering was also applied when loading the hm association, which resulted in the error.

This patch only applies the ordering the the hm-relation if we are performing a join (2).
Otherwise the order will only appear in the second query (1).
2013-02-24 20:51:39 +01:00
Xavier Noria
d65376fce4 Merge pull request #9400 from senny/remove_auto_explain_threshold_in_seconds
remove config.auto_explain_threshold_in_seconds
2013-02-24 11:16:35 -08:00
Yves Senn
d3688e02ca remove AR auto-explain (config.auto_explain_threshold_in_seconds)
We discussed that the auto explain feature is rarely used.
This PR removes only the automatic explain. You can still display
the explain output for any given relation using `ActiveRecord::Relation#explain`.

As a side-effect this should also fix the connection problem during
asset compilation (#9385). The auto explain initializer in the `ActiveRecord::Railtie`
forced a connection.
2013-02-24 20:01:04 +01:00
Rafael Mendonça França
e54acf1308 Do not type cast all the database url values.
We should only type cast when we need to use.

Related to 4b005fb371c2e7af80df7da63be94509b1db038c
2013-02-24 14:36:18 -03:00
Yves Senn
d98763a602 multiple actions for :on option with after_commit and after_rollback
Closes #988.
2013-02-21 15:02:52 +01:00
Xavier Noria
8fc6b9b4c8 ActiveRecord -> Active Record [ci skip] 2013-02-20 21:09:11 +01:00
Xavier Noria
aeb4592006 removes relation bang methods from the AR changelog [ci skip] 2013-02-20 20:37:00 +01:00
Xavier Noria
36113d0b79 puts a lambda around a default scope [ci skip] 2013-02-20 20:37:00 +01:00
Xavier Noria
c5115b06d7 database.yml -> config/database.yml [ci skip] 2013-02-20 20:36:59 +01:00