Commit Graph

31383 Commits

Author SHA1 Message Date
Francesco Rodriguez
629bc03bf8 change param name to improve documentation
The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

    # Returns +true+ if the error messages include an error for the given
    # +attribute+, +false+ otherwise.
    #
    #   person.errors.messages # => { :name => ["can not be nil"] }
    #   person.errors.include?(:name) # => true
    #   person.errors.include?(:age)  # => false
    def include?(attribute)
      (v = messages[attribute]) && v.any?
    end
2012-06-22 12:42:32 -05:00
Vijay Dev
35ee8fa3d8 Merge branch 'master' of github.com:lifo/docrails 2012-06-22 22:15:27 +05:30
Vijay Dev
6285675db1 fixes a few mistakes in api docs [ci skip] 2012-06-22 22:14:29 +05:30
Vijay Dev
741cb5b12b copy edit the assets guide[ci skip] 2012-06-22 22:07:21 +05:30
Rafael Mendonça França
fb8cf55868 Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributes
Dynamic finders for aliased attributes
2012-06-22 07:51:11 -07:00
Maximilian Schneider
f984b8152f made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual
column name and not its alias defined with #alias_attribute
2012-06-22 16:44:01 +02:00
Carlos Antonio da Silva
9298d60af0 Fix changelog typo [ci skip] 2012-06-22 09:44:30 -03:00
Carlos Antonio da Silva
d59b2ab5c1 Merge branch 'pluck-multiple-columns'
Allow ActiveRecord::Relation#pluck to accept multiple columns. Returns an
array of arrays containing the type casted values:

    Person.pluck(:id, :name)
    # SELECT people.id, people.name FROM people
    # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]

Closes #6500
2012-06-22 09:40:39 -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
Carlos Antonio da Silva
6aae17e856 Refactor pluck with multiple columns
Ensure it works with mix of symbols and strings, and with a select
clause possibly containing more than one column.

Also remove support for pluck with an array of columns, in favor of
passing the list of attributes:

    Model.pluck(:a, :b)

See comments: https://github.com/rails/rails/pull/6500#issuecomment-6030292
2012-06-22 09:15:43 -03:00
jeroeningen
2e379c1e63 ActiveRecord#pluck now accepts multiple columns 2012-06-22 08:35:36 -03:00
Carlos Antonio da Silva
8b173f3bc5 Fix serializable_hash with xml generation and default :except option
When generating xml with a custom implementation of serializable_hash,
if using the :except option, it was being overriden by the default AR
implementation that attempts to ignore the inheritance column from STI
automatically. So, if you have an implementation like this:

    def serializable_hash(options={})
      super({ except: %w(some_attr) }.merge!(options))
    end

The :except option was correctly being used for :json generation, but
not for :xml, because the options hash already contained the :except
key with the inheritance column, thus overriding the customization.

This commit fixes this problem by removing the :except logic from the
xml serializer, that happened before calling serializable_hash. Since
serializable_hash also does the same check for inheritance column, this
logic was duplicated in both places, thus it's safe to remove it from
xml serializer (see ActiveRecord::Serialization#serializable_hash).

This is an attempt to solve issue #2498, that claims for a
"Single transformation API for both xml and json representations".
2012-06-22 08:28:26 -03:00
Carlos Antonio da Silva
965b779eb2 Add some coverage for AR serialization with serializable_hash
ActiveRecord json/xml serialization should use as base
serializable_hash, provided by ActiveModel. Add some more coverage
around options :only and :except for both json and xml serialization.
2012-06-22 08:28:03 -03:00
Jon Leighton
70d3625760 disallow mutating a relation once loaded 2012-06-22 10:29:49 +01:00
Andrew White
bacfa9d1ca It's AR::Reflection not AR::Relation 2012-06-22 10:19:34 +01:00
Francesco Rodriguez
d569bfed0d update ActiveModel::Callbacks documentation [ci skip] 2012-06-22 00:32:54 -05: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
4bbd35f7a6 Set the hash value directly instead of using merge! 2012-06-21 22:54:18 -03:00
Francesco Rodriguez
c3025e8d59 add description to ActiveModel::MissingAttributeError [ci skip] 2012-06-21 16:56:40 -05:00
Rafael Mendonça França
a4cc79d061 Merge pull request #6818 from frodsan/add_nodoc_instancemethod
add :nodoc: to AM::AttributeMethods#instance_method_already_implemented?...
2012-06-21 14:48:36 -07:00
Francesco Rodriguez
1ce803d091 add :nodoc: to AM::AttributeMethods#instance_method_already_implemented? [ci skip] 2012-06-21 16:40:17 -05:00
Francesco Rodriguez
95a938a5e6 add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci skip] 2012-06-21 16:19:40 -05:00
Aaron Patterson
6d71080530 use mutex_m rather than use a delegate system 2012-06-21 13:54:14 -07:00
Francesco Rodriguez
f975c4b641 add docs to AM::AttributeMethods#define_attribute_method [ci skip] 2012-06-21 15:51:37 -05:00
Yehuda Katz
a010fc1800 Merge pull request #6428 from pinetops/resolver_concurrency_fix
Make the Resolver template cache threadsafe
2012-06-21 13:47:18 -07:00
Rafael Mendonça França
6688cd2b44 Merge pull request #6815 from frodsan/add_nodoc_attrmethodmatcher
add :nodoc: to AM::AttributeMethods::AttributeMethodMatcher
2012-06-21 13:43:09 -07:00
Francesco Rodriguez
1cb2cb8bea add :nodoc: to AM::AttributeMethods::AttributeMethodMatcher [ci skip] 2012-06-21 15:37:09 -05:00
Aaron Patterson
188cc90af9 stop subclassing string 2012-06-21 12:13:13 -07:00
Francesco Rodriguez
b5b350ad5c fix ActiveModel::AttributeMethods#alias_attribute documentation [ci skip] 2012-06-21 12:51:39 -05:00
Francesco Rodriguez
bf3332bfdf update ActiveModel::AttributeMethods documentation [ci skip] 2012-06-21 12:26:14 -05:00
Carlos Antonio da Silva
e76ced0620 Merge pull request #6804 from acapilleri/firm_changes_from_zero_to_string
changed the firm of changes_from_zero_to_string?
2012-06-21 05:37:36 -07:00
Carlos Antonio da Silva
682d247ca4 Merge pull request #6806 from chancancode/add_test_singularize_of_irregularity
Inflector: Added missing tests cases to ensure idempotency of singularize and pluralize
2012-06-21 05:35:31 -07:00
Carlos Antonio da Silva
e769559a93 Merge pull request #6808 from arunagw/warning_removed_actionpack
Removed warnings.
2012-06-21 05:22:32 -07:00
Arun Agrawal
6f6111e089 Removed warnings.
1. Change in test name as already defined.
2. ambiguous first argument; put parentheses or 
even spaces
2012-06-21 17:01:57 +05:30
Godfrey Chan
84213613c3 Small typo in Backporting instructions. 2012-06-21 02:19:32 -07:00
Godfrey Chan
fe933be5e2 Adds missing inflector tests to ensure idempotency
This is a follow up to #4719. It appears that singularize and pluralize
are supposed to be idempotent - i.e. when you call singularize or
pluralize multiple times on the same string, you should get the same
result. (At least for the "officially supported" cases that the stock
inflector is designed to handle.) #4719 added the missing tests for
regular cases, and this commit added the missing tests for the
irregularities.

While I'm at that, I also synced up the irregularity test cases with
the current set of irregularity cases that we ship out-of-the-box.
2012-06-21 02:16:48 -07:00
Angelo capilleri
c3a5be0129 changed the firm of changes_from_zero_to_string?
delete *column* because is unused by the method.
2012-06-21 09:32:44 +02:00
Aaron Patterson
26a4e5e60e logger is a singleton, just flush the singleton 2012-06-20 14:21:23 -07:00
Aaron Patterson
8edd6deae8 explain listener does not care about time, so use evented listener 2012-06-20 14:20:55 -07:00
Aaron Patterson
b9f9951d5f use thread local queues.
Log listener is a singleton shared across threads, so make sure the
event queues are local to each thread.
2012-06-20 13:22:11 -07:00
Rafael Mendonça França
c1c4ecb9db Merge pull request #6801 from dmathieu/mailer_raise_if_no_implicit_template
Mailer with no implicit template
2012-06-20 13:09:54 -07:00
Damien Mathieu
45b1045d16 raise an error if no implicit mailer template could be found 2012-06-20 22:06:31 +02:00
Rafael Mendonça França
b046ea452c Merge pull request #6799 from kennyj/refactor_long_codes
Refactor testcase codes. It's repeated.
2012-06-20 11:39:49 -07:00
kennyj
4d6853946d Refactor testcase codes. It's repeated. 2012-06-21 03:26:32 +09:00
Carlos Antonio da Silva
323ee207cb Merge pull request #6798 from kennyj/db-rake-structure-load
Refactor db:structure:load task.
2012-06-20 10:12:27 -07:00
Rafael Mendonça França
1bdc098d97 Merge pull request #4396 from kennyj/fix_4259
Fix GH #4259. When we execute schema dumper, we must remove table_name_prefix and table_name_suffix.
2012-06-20 14:08:23 -03:00
kennyj
30c84aabab Remove duplicated codes. 2012-06-21 01:49:52 +09:00
kennyj
19911959d9 Refactor db:structure:load task. 2012-06-21 01:35:26 +09:00
Damien Mathieu
a4726d3805 just specify what's to be done, not what's not to be. 2012-06-20 18:23:57 +03:00
Ben Oakes
d0f088e7f5 Fix delivery_method usage 2012-06-20 12:09:53 -03:00