Commit Graph

337 Commits

Author SHA1 Message Date
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
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
Yves Senn
de615b38b3 unify AR changelog entries [ci skip] 2013-02-20 18:29:44 +01:00
Yves Senn
39eef1a565 also rename indexes when a table or column is renamed
When a table or a column is renamed related indexes kept their name. This will lead to confusing names. This patch renames related indexes when a column or a table is renamed. Only indexes with names generated by rails will be renamed. Indexes with custom names will not be renamed.
2013-02-20 18:19:25 +01:00
Xavier Noria
20ed3e0f71 moves the new :nsec date format to the Active Support changelog [ci skip] 2013-02-20 18:08:55 +01:00
Yves Senn
cca43528d4 reserve index name chars for internal rails operations
Some adapter (SQLite3) need to perform renaming operations to support
the rails DDL. These rename prefixes operate with prefixes. When an
index name already uses up the full space provieded by
`index_name_length` these internal operations will fail. This patch
introduces `allowed_index_name_length` which respects the amount of
characters used for internal operations. It will always be <=
`index_name_length` and every adapter can define how many characters
need to be reserved.
2013-02-20 17:50:10 +01:00
Rafael Mendonça França
7bae72c69f Merge pull request #9332 from wangjohn/adding_documentation_to_error_raising_in_query_methods
Tests to make sure empty arguments in WhereChain raise errors
2013-02-20 08:38:50 -08:00
wangjohn
d49f862b9a Added comments about the check_empty_arguments method which is called
for query methods in a where_clause. Also, modified the CHANGELOG entry
because it had false information and added tests.
2013-02-20 10:53:25 -05:00
wangjohn
67d8bb963d Reduced memory leak problem in transactions by lazily updating AR objects with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks. 2013-02-20 10:51:28 -05:00
Yves Senn
0a6b61a5f5 descriptive error message when AR adapter was not found. Closes #7313. 2013-02-20 10:54:58 +01:00
Xavier Noria
276918098a s/revertible/reversible/ 2013-02-19 18:12:54 +01:00
Xavier Noria
ff259b5249 moves a CHANGELOG entry from AR to AP 2013-02-19 17:32:32 +01:00
Xavier Noria
2abf217d54 small tweaks in the AR CHANGELOG 2013-02-19 17:32:32 +01:00
John J Wang
4033c50000 Raise an error when query methods have blank arguments, and when blank arguments are meaningless. 2013-02-19 11:15:15 -05:00
Andrew White
bd328f4342 Add CHANGELOG entry for 41ff6a10216f48f43605a1f9cd6094765cab750f
[ci skip]
2013-02-17 16:48:01 +00:00
Yves Senn
4a4ff50459 don't cache invalid subsets when preloading hmt associations.
closes #8423.
2013-02-14 17:46:07 +01:00
James Miller
caabed6c76 Don't call after_commit when creating through an association and save fails, fixes #5802 2013-02-13 12:27:06 -08:00
Sergey Nartimov
9dfef5a46b define Active Record Store accessors in a module
Allow store accessors to be overrided like other attribute methods,
e.g.:

    class User < ActiveRecord::Base
      store :settings, accessors: [ :color, :homepage ], coder: JSON

      def color
        super || 'red'
      end
    end
2013-02-11 17:00:55 +03:00
Guillermo Iguaran
9c5cc89ede Update activerecord/CHANGELOG.md 2013-02-09 12:23:32 -05:00
Guillermo Iguaran
29f3a036e7 Reverting e170014113 (Change behaviour with empty hash in where clause) 2013-02-08 16:53:49 -05:00