Commit Graph

10630 Commits

Author SHA1 Message Date
Sean Griffin
d849f42b4e Autosave existing records on HMT associations when the parent is new
To me it seems like this should only be the case if `autosave: true` is
set on the association. However, when implemented that way, it caused
issues with has many associations, where we have explicit tests stating
that child records are updated when the parent is new, even if autosave
is not set (presumably to update the parent id, but other changed
attributes would be persisted as well).

It's quirky, but at least we should be consistently quirky. This
constitutes a minor but subtle change in behavior, and therefore should
not be backported to 4.2 and earlier.

Fixes #19782
2015-04-18 10:47:04 -04:00
Yves Senn
228559eab8 Merge pull request #19787 from Senjai/patch-2
[Doc] Encourage users to user super to override methods.

[ci skip]
2015-04-18 13:03:51 +02:00
Richard Wilson
8f7d9eb043 Encourage users to user super to override methods.
IMO we shouldn't encourage users to use methods they shouldn't need to know about. As Song (in this example) inherits from ActiveRecord, we can use super here instead to get the same effect with the bonus of not knowing how active record actually implements these methods.
2015-04-16 16:46:03 -07:00
Yves Senn
5f00ed10dd Revert "Merge pull request #19755 from yuki24/activerecord/support-for-set"
This reverts commit 524d40591eaa2f4d007409bfad386f6b107492eb, reversing
changes made to 34d3a6095100245283861ef480a54d0643bbee4c.

Reasoning behind the revert are in the PR discussion:
https://github.com/rails/rails/pull/19755

- This means that types can no longer cast to/from `Set`, and reasonably
  work with `where` (we already have this problem for `array`/`json`
  types on pg)
- This adds precedent for every other `Enumerable`, and we can't target
  `Enumerable` directly.
- Calling `to_a` on a `Set` is reasonable.
2015-04-15 09:10:00 +02:00
Yuki Nishijima
50cae600bd Add support for Set to Relation#where
Previously `#where` used to treat `Set`objects as nil, but now it treats
them as an array:

  set = Set.new([1, 2])
  Author.where(:id => set)
  # => SELECT "authors".* FROM "authors" WHERE "authors"."id" IN (1, 2)
2015-04-13 20:13:37 -07:00
Grey Baker
e91c4339e4 Document that partial indexes are only supported by Postgres and SQLite.
Fixes #18106
2015-04-13 09:33:48 +02:00
Zachary Scott
e83c398f60 Add a note regarding add_column restricted API [ci skip]
We should document current behavior, and this is design of API for now.

Closes #17597
2015-04-12 21:01:55 -07:00
Zachary Scott
93d2eeaad5 Apply edits from @senny to close #19397 [ci skip] 2015-04-12 18:17:31 -07:00
Zachary Scott
055d9993b5 Merge branch 'patch-1' 2015-04-12 17:58:56 -07:00
wingfire
a9f2c124af Enhance documentation of pluck with a hint to ids [ci skip]
Documentation is giving an example that can be replaced by a more dry command.
Give a hint that ids can be used instead of pluck(:id).
2015-04-12 17:57:00 -07:00
Mehmet Emin İNAÇ
29986b0d41 Missing note on validates_presence_of validation [ci skip]
Without this note, someone can misunderstand the usage of validates_presence_of method

add missing note for the validates_presence_of
2015-04-11 23:24:36 +03:00
Simon Stemplinger
41b2ba5926 fix documentation for SchemaStatements#add_foreign_key
The implementation of the generation of the foreign key name was changed
between Rails 4.2.0 and 4.2.1 from a random to a deterministic behavior,
however the documentation still describes the old randomized behavior.
2015-04-08 22:02:00 +02:00
Arthur Neves
8971389783
Batch touch parent records
[fixes #18606]

Make belongs_to use touch over touch_later when running the callbacks.

Add more tests and small method rename

Thanks Jeremy for the feedback.
2015-04-08 13:31:28 -04:00
Andrey Voronkov
1a36be390e Fix uniqueness validation with out of range value 2015-04-08 19:28:45 +03:00
Rafael Mendonça França
d69d662e65 Merge pull request #19680 from vngrs/make_join_model_name_const_private
Change join model name constant to private constant
2015-04-07 16:16:08 -03:00
Jeremy Kemper
bd51bbc028 Merge pull request #17574 from kamipo/charset_collation_options
Add charset and collation options support for MySQL string and text columns.
2015-04-07 09:40:16 -07:00
Mehmet Emin İNAÇ
b34c98153f Change join model name constant to private constant
This will resolve the fixme message which is about making constant invisible.
2015-04-07 11:29:04 +03:00
Rafael Mendonça França
d5f80655f9 Merge pull request #19647 from codeout/association_update
Fix a regression introduced by removing unnecessary db call when replacing
2015-04-06 19:17:54 -03:00
Rafael Mendonça França
c539cc0061 Merge pull request #19448 from tgxworld/fix_activesupport_callbacks_clash_on_run
Fix AS::Callbacks raising an error when `:run` callback is defined.
2015-04-06 18:58:19 -03:00
Rafael Mendonça França
a956ec9640 No need to document drop_table in the PostgreSQLAdapter
It behaves in the same way that the abstract adapter.

[ci skip]
2015-04-06 17:38:53 -03:00
Mehmet Emin İNAÇ
acd21df91a change the explanation of :if_exists option [ci skip] 2015-04-06 19:33:36 +03:00
Mehmet Emin İNAÇ
1a53549901 drop_table method documentation for mysql and postgresql adapters [ci skip] 2015-04-06 16:15:15 +03:00
Yves Senn
51eacc71c7 Merge pull request #19652 from vngrs/pluralize_foreign_key_table_name_bug
use singular table name if pluralize_table_names is setted as false whil...
2015-04-06 10:42:44 +02:00
Mehmet Emin İNAÇ
8c1180731f use singular table name if pluralize_table_names is setted as false while creating foreign key
test case for use singular table name if pluralize_table_names is setted as false while creating foreign key

refactor references foreign key addition tests

use singular table name while removing foreign key

merge foreign key singular table name methods

remove unnecessary drop table from test
2015-04-06 11:10:24 +03:00
eileencodes
191facc857 Don't invoke sql_runtime if logger is not set to info
`sql_runtime` was getting invoked even when the logger was set to fatal.
This ensures that does not happen by checking that the logger is set to
info level before logging the view runtime.

This reduces the number of times `sql_runtime` is called for integration
tests with a fatal logger from 6 to 2.
2015-04-04 09:21:18 -04:00
Shintaro Kojima
e646d3bf57 Fix a regression introduced by removing unnecessary db call when replacing
When replacing a has_many association with the same one, there is nothing to do with database but a setter method should still return the substituted value for backward compatibility.
2015-04-04 12:48:36 +00:00
Koen Punt
9452dc9c0a remove duplicates 2015-04-03 00:00:30 +02:00
brainopia
58d75fd811 Freeze static arguments for gsub 2015-04-02 02:15:07 +03:00
brainopia
cdac52e124 Prefer string patterns for gsub
https://github.com/ruby/ruby/pull/579 - there is a new optimization
since ruby 2.2

Previously regexp patterns were faster (since a string was converted to
regexp underneath anyway). But now string patterns are faster and
better reflect the purpose.

  Benchmark.ips do |bm|
    bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') }
    bm.report('string') { 'this is ::a random string'.gsub('::', '/') }
    bm.compare!
  end
  # string: 753724.4 i/s
  # regexp: 501443.1 i/s - 1.50x slower
2015-04-02 02:07:45 +03:00
Rafael Mendonça França
baa176e3f0 Merge pull request #19586 from mechanicles/fix-eager-loading-for-find-methods
Fix eager loading association using default_scope for finder methods.
2015-03-31 15:06:22 -03:00
Santosh Wadghule
4596e16f1a Fix eager loading association using default_scope for finder methods.
- Eager loading was not working for the default_scope (class method)
  for 'find' & 'find_by' methods.
- Fixed these by adding a new check 'respond_to?(:default_scope)'.
2015-03-31 22:54:42 +05:30
Rafael Mendonça França
c8bd12cf5a Make method as nodoc since we are already docummenting at AbstractAdapter 2015-03-31 13:29:18 -03:00
Alexander Dimitriyadi
868816734d [ci skip] Combine complementary AR #find doc lines 2015-03-30 14:07:55 -04:00
Sean Griffin
01421d5b62 Clarify the role of ActiveRecord::Core.encode_with
Fixes #19568
2015-03-29 14:10:20 -06:00
Sean Griffin
445c12f7df Reduce memory usage when loading types in PG
We were never clearing the `PG::Result` object used to query the types
when the connection is first established. This would lead to a
potentially large amount of memory being retained for the life of the
connection.

Investigating this issue also revealed several low hanging fruit on the
performance of these methods, and the number of allocations has been
reduced by ~90%.

Fixes #19578
2015-03-29 13:54:39 -06:00
Jon Atack
fe6de0f023 [skip ci] Improve warn_on_records_fetched documentation
- ‘dection’ -> ‘detection’

- ‘exceeds threshold’ -> ‘exceeds the threshold’

- Other minor improvements.
2015-03-27 15:36:44 +05:30
Sean Griffin
cd09261846 Partially merge #17650
Merges 647eb2cf1cd65b0391e3584361f0fc76246e64f3. The pull request as a
whole is quite large, and I'm reviewing the smaller pieces individually.
2015-03-26 17:41:47 -06:00
Sean Griffin
3b50a7a3e1 Partially merge #17650
Merges 1d8d5a74b81b8aab1f5e6d233d509a92525ed4e1. The pull request as a
whole is quite large, and I'm reviewing the smaller pieces individually.
2015-03-26 17:36:42 -06:00
Rafael Mendonça França
8b451e3a31 Merge pull request #18846 from hundredwatt/feat/warn-on-result-set-size
Add `config.active_record.warn_on_result_set_size` option
2015-03-26 17:21:36 -03:00
Vijay Dev
c26ee64b92 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/4_0_release_notes.md
2015-03-26 16:22:41 +00:00
Jason Nochlin
4d6fbe2934 Add config.active_record.warn_on_records_fetched_greater_than option
When set to an integer, a warning will be logged whenever a result set
larger than the specified size is returned by a query. Fixes #16463

The warning is outputed a module which is prepended in an initializer,
so there will be no performance impact if
`config.active_record.warn_on_records_fetched_greater_than` is not set.
2015-03-25 16:50:11 -04:00
Lars Kanis
647eb2cf1c PostgreSQL, Use ruby-pg's built-in capabilities for array en-/decoding in C.
This obsoletes the ruby based implementations.
2015-03-25 15:05:24 +01:00
Lars Kanis
1d8d5a74b8 PostgreSQL, Fix OID based type casts in C for primitive types.
The type map was introduced in aafee23, but wasn't properly filled.

This mainly adjusts many locations, that expected strings instead of
integers or boolean.

add_pg_decoders is moved after setup of the StatementPool, because
execute_and_clear could potentially make use of it.
2015-03-25 15:05:23 +01:00
Lars Kanis
9f2f268666 PostgreSQL, Add input type casts for primitive types.
Ruby-pg's default way to serialize values for transmission to the database is to
call #to_s . This however creates a temporary String object for each value.
Setting a class based type map avoids the allocation of this additional String.

The performance benefit is measurable in microbenchmarks, but not with
the overhead of activerecord. However it's free to use and has no drawback.
2015-03-25 15:05:23 +01:00
Jason Weathered
78fb8bb7e1 Avoid loading user's psqlrc when loading test structure 2015-03-25 09:21:16 +10:00
Rafael Mendonça França
d024bad4d1 Revert "Merge pull request #19500 from ccutrer/dry_sti_subclass_finding"
This reverts commit 5cfa6a8ab997089c3012a82052c8c317b2e095f5, reversing
changes made to bfd5bf8313e6ea0bb2eccb68ee5076bb63f0b2db.

Reason: This broken travis build.
2015-03-24 14:12:24 -03:00
Cody Cutrer
7be08818a9 DRY up STI subclass logic
the newer method used for discriminating new records did not
use the older and more robust method used for instantiating
existing records, but did have a better post-check to ensure
the sublass was in the hierarchy. so move the descendants check
to find_sti_class, and then simply call find_sti_class from
subclass_from_attributes
2015-03-24 09:22:46 -06:00
Carlos Antonio da Silva
bfd5bf8313 Merge pull request #19452 from pinglamb/fix-referencing-wrong-alias-when-joining-tables-of-has-many-through-association
Fix referencing wrong aliases while joining tables of has many through association
2015-03-24 08:00:59 -03:00
yui-knk
dbc7acd8ef [ci skip] Remove unacceptable method name 2015-03-24 13:23:12 +09:00
Rafael Mendonça França
ca5a35da37 Merge pull request #19449 from Gaurav2728/gaurav-unavailable_link
remove old unavailable link with relevant fix patch 1
2015-03-23 03:08:41 -03:00