Commit Graph

441 Commits

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