Commit Graph

10566 Commits

Author SHA1 Message Date
amitkumarsuroliya
7f90d97521 Updated MySQL documentation link to latest version MySQL 5.6 [ci skip] 2015-03-19 20:34:33 +05:30
Yves Senn
ac291b76ea Merge pull request #19407 from amitsuroliya/mysql_adapter_doc
Updated MySQL documentation link for STRICT_ALL_TABLES [ci skip]
2015-03-19 16:00:41 +01:00
amitkumarsuroliya
b4e550ce46 Updated MySQL documentation link for STRICT_ALL_TABLES 2015-03-19 20:26:32 +05:30
Damien Mathieu
d578cbfb5c don't fallback to RACK_ENV when RAILS_ENV is not present 2015-03-19 10:06:28 +01:00
eileencodes
cce5126eb2 Add clear_association_scope_cache method
In the tests if I were to call `post.categorizations.to_a` and then later call
`post.categorizations.to_a` expecting to have different results the 2 queries
would be the same because of the caching involved in
`@association_scope_cache`. The chain gets cached and the queries will
be the same even if they are not supposed to be (i.e. testing an order
dependent scoping issue).

I found this issue because I was working on a bug with cached scoped
in hm:t and hm:t polymorphic relationships but `capture_sql` was
outputting the wrong SQL to write a good test.
2015-03-18 08:13:53 -04:00
Yves Senn
08615a3bcb Merge pull request #19348 from Empact/null-scope
Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.

Conflicts:
	activerecord/CHANGELOG.md
2015-03-18 11:20:47 +01:00
Alexander Leishman
6901a27207 Update old link in pessimistic.rb comments
Update link in comments to point to latest MySQL production version documentation. See here for reference: http://dev.mysql.com/doc/refman/5.0/en/choosing-version.html
2015-03-18 16:41:37 +08:00
Ben Woosley
3bcb314998 Fix NullRelation.update_all and .exists? signature to match the same on Relation 2015-03-18 00:46:09 -07:00
Ryan Wallace
7ab36f4532 Add config.active_record.dump_schemas.
Fixes db:structure:dump when using schema_search_path and PostgreSQL
extensions.

Closes #17157.
2015-03-17 10:43:26 -07:00
Ben Woosley
38ccfe689d Drop references_eager_loaded_tables? test from has_include?
It is redundant with tests in `eager_loading?`, but for the difference
between `includes_values.present?` and `includes_values.any?`, which
is a difference without a distinction because `false` has no meaning
for `includes`.
2015-03-17 04:59:50 -07:00
keepcosmos
ca86c9e8f9 reflection doc fix about hierarchy 2015-03-17 10:03:32 +09:00
Rafael Mendonça França
8f3bd3db49 Merge pull request #19359 from yahonda/mysql_subclient
Materialize subqueries by adding `DISTINCT` to suport MySQL 5.7.6 and later
2015-03-16 19:10:37 -03:00
Brandon Weiss
0965863564 Closes rails/rails#18864: Renaming transactional fixtures to transactional tests
I’m renaming all instances of `use_transcational_fixtures` to
`use_transactional_tests` and “transactional fixtures” to
“transactional tests”.

I’m deprecating `use_transactional_fixtures=`. So anyone who is
explicitly setting this will get a warning telling them to use
`use_transactional_tests=` instead.

I’m maintaining backwards compatibility—both forms will work.
`use_transactional_tests` will check to see if
`use_transactional_fixtures` is set and use that, otherwise it will use
itself. But because `use_transactional_tests` is a class attribute
(created with `class_attribute`) this requires a little bit of hoop
jumping. The writer method that `class_attribute` generates defines a
new reader method that return the value being set. Which means we can’t
set the default of `true` using `use_transactional_tests=` as was done
previously because that won’t take into account anyone using
`use_transactional_fixtures`. Instead I defined the reader method
manually and it checks `use_transactional_fixtures`. If it was set then
it should be used, otherwise it should return the default, which is
`true`. If someone uses `use_transactional_tests=` then it will
overwrite the backwards-compatible method with whatever they set.
2015-03-16 11:35:44 -07:00
Yasuo Honda
4794a9a6c1 Materialize subqueries by adding DISTINCT
to support MySQL 5.7.6 `optimizer_switch='derived_merge=on'`
2015-03-16 17:05:47 +00:00
Ben Woosley
c82cc222c7 Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.
When a new record has the necessary information prior to save, we can
avoid busting the cache.

We could simply clear the @proxy on #reset or #reset_scope, but that
would clear the cache more often than necessary.
2015-03-15 17:29:05 -07:00
eileencodes
51660f0191 Fix leaky chain on polymorphic association
If there was a polymorphic hm:t association with a scope AND second
non-scoped hm:t association on a model the polymorphic scope would leak
through into the call for the non-polymorhic hm:t association.

This would only break if `hotel.drink_designers` was called before
`hotel.recipes`. If `hotel.recipes` was called first there would be
no problem with the SQL.

Before (employable_type should not be here):
```
SELECT COUNT(*) FROM "drink_designers" INNER JOIN "chefs" ON
"drink_designers"."id" = "chefs"."employable_id" INNER JOIN
"departments" ON "chefs"."department_id" = "departments"."id" WHERE
"departments"."hotel_id" = ? AND "chefs"."employable_type" = ?
[["hotel_id", 1], ["employable_type", "DrinkDesigner"]]
```

After:
```
SELECT COUNT(*) FROM "recipes" INNER JOIN "chefs" ON "recipes"."chef_id"
= "chefs"."id" INNER JOIN "departments" ON "chefs"."department_id" =
"departments"."id" WHERE "departments"."hotel_id" = ?  [["hotel_id", 1]]
```

From the SQL you can see that `employable_type` was leaking through when
calling recipes. The solution is to dup the chain of the polymorphic
association so it doesn't get cached. Additionally, this follows
`scope_chain` which dup's the `source_reflection`'s `scope_chain`.

This required another model/table/relationship because the leak only
happens on a hm:t polymorphic that's called before another hm:t on the
same model.

I am specifically testing the SQL here instead of the number of records
becasue the test could pass if there was 1 drink designer recipe for the
drink designer chef even though the `employable_type` was leaking through.
This needs to specifically check that `employable_type` is not in the SQL
statement.
2015-03-15 10:39:42 -04:00
keepcosmos
a862a57683 Doc fix about association hierarchy 2015-03-15 16:48:07 +09:00
Arthur Neves
0d76ab9c6f Fix before_commit when updating a record on the callback 2015-03-14 12:20:36 -04:00
Carlos Antonio da Silva
6b5f815cf8 Merge pull request #19301 from Empact/default-scopes
Isolate access to .default_scopes in ActiveRecord::Scoping::Default
2015-03-12 09:36:14 -03:00
Ben Woosley
c1deb81cd0 Isolate access to .default_scopes in ActiveRecord::Scoping::Default
Instead use .scope_attributes? consistently in ActiveRecord to check whether
there are attributes currently associated with the scope.

Move the implementation of .scope_attributes? and .scope_attributes to
ActiveRecord::Scoping because they don't particularly have to do specifically
with Named scopes and their only dependency, in the case of
.scope_attributes?, and only caller, in the case of .scope_attributes is
contained in Scoping.
2015-03-12 01:22:39 -07:00
Matt Brictson
ba7532700f Require pg~>0.18 to ensure Ruby 2.2 compatibility
Versions of the pg gem earlier than 0.18.0 cannot be used safely with Ruby 2.2.
Specifically, pg 0.17 when used with Ruby 2.2 has a known bug that causes
random bits to be added to the end of strings. Further explanation here:
https://bitbucket.org/ged/ruby-pg/issue/210/crazy-bytes-being-added-to-record
2015-03-11 22:23:36 -07:00
Jeremy Kemper
d31c941413 Revert "Merge pull request #15476 from JacobEvelyn/master"
This introduces undesirable `Rails.logger` formatters (such as the syslog
formatter) onto a `Logger.new(STDERR)` for the console. The production
logger may be going elsewhere than standard io, so we can't presume to
reuse its formatter.

With syslog, this causes missing newlines in the console, so irb prompts
start at the end of the last log message.

We can work to expose the console formatter in another way to address
the original issue.

This reverts commit 026ce5ddf11c4cda0aae7f33a9266e54117db318, reversing
changes made to 6f0a69c5899ebdc892e2aa23e68e2604fa70fb73.
2015-03-11 15:06:42 -07:00
Yves Senn
0c7c6286f6 pg, disable_referential_integrity only catches AR errors.
This change was prompted by 598b841.
2015-03-11 14:34:53 +01:00
Yves Senn
598b841882 fix typo in transaction argument. Closes #19265.
There was a typo in the `:requires_new` option. This led
to `#<ArgumentError: unknown keyword: require_new>` leaving all the
triggers in a disabled state.
2015-03-11 14:21:26 +01:00
Sean Griffin
4e7217027f Add YAML compatibility for objects from Rails 4.2
As of Ruby 2.2, Psych can handle any object which is marshallable. This
was not true on previous versions of Ruby, so our delegator types had to
provide their own implementation of `init_with` and `encode_with`.
Unfortunately, this doesn't match up with what Psych will do today.

Since by the time we hit this layer, the objects will have already been
created, I think it makes the most sense to just grab the current type
from the class.
2015-03-10 11:56:45 -06:00
Sean Griffin
afc124c3b4 Attempt to provide backwards compatible YAML deserialization
I should have done this in the first place. We are now serializing an
explicit version so we can make more careful changes in the future. This
will load Active Record objects which were serialized in Rails 4.1.

There will be bugs, as YAML serialization was at least partially broken
back then. There will also be edge cases that we might not be able to
handle, especially if the type of a column has changed.

In addition, we're passing this as `from_database`, since that is
required for serialized columns at minimum. All other types were
serializing the cast value. At a glance, there should be no types for
which this is a problem.

Finally, dirty checking information will be lost on records serialized
in 4.1, so no columns will be marked as changed.
2015-03-10 11:56:45 -06:00
Rafael Mendonça França
08469012e4 Merge pull request #19275 from keepcosmos/remove-autoload-path
remove unnecessary autoload path parameters
2015-03-10 13:57:56 -03:00
Gaurav Sharam
434c768a7d ‘test_after_commit’ gem is not required in Rails 5 remove note from doc 2015-03-10 18:13:07 +05:30
keepcosmos
f7233b27f2 remove unnecessary path parameters 2015-03-10 21:29:59 +09:00
Arthur Nogueira Neves
095f4c9da3 Merge pull request #18200 from brainopia/rollback_frozen_records
Fix rollback of frozen records
2015-03-07 18:56:24 -05:00
Kasper Timm Hansen
387e7be458 Merge pull request #19234 from sivsushruth/doc_fix
Doc fix [ci skip]
2015-03-07 01:02:40 +01:00
Sushruth Sivaramakrishnan
6fe13e5296 Doc fix [ci skip] 2015-03-07 04:38:25 +05:30
Prathamesh Sonpatki
88199f7f03 Updated documentation of CollectionProxy#clear [ci skip]
- CollectionProxy#clear method calls delete_all so the SQL is directly
   run into the database.
 - So the updated_at column of the object on which its run is not
   updated.
 - Closes #17161
2015-03-06 21:53:07 +05:30
Robin Dupret
d969405acd Some documentation edits [ci skip]
* Fix a few typos
* Wrap some lines around 80 chars
* Rephrase some statements
2015-03-05 14:18:09 +01:00
brainopia
caae79a385 Fix transaction state for unsynced records when entering transaction 2015-03-04 15:24:03 +03:00
brainopia
8313797810 Fix rollback of frozen records 2015-03-04 15:23:25 +03:00
Ryuta Kamizono
6fa6c739d1 Correctly dump serial and bigserial 2015-03-04 17:52:11 +09:00
Ryuta Kamizono
5366cc6b55 Add Column#bigint? method 2015-03-04 17:51:47 +09:00
Yves Senn
b0edabf3be Merge pull request #19176 from imajes/master
Fixes reference for schema_format to AR::Base from AS::Base
2015-03-03 19:52:08 +01:00
James Cox
e3a1bd3560 Fixes reference for schema_format to AR::Base from AS::Base 2015-03-03 12:13:18 -05:00
Sean Griffin
1a6c3f0a2e Merge pull request #19171 from JuanitoFatas/doc/more-examples
Add more documents for AR connection_adapters abstract schema_definitions. [ci skip]
2015-03-02 21:19:54 -07:00
Juanito Fatas
d62b8f8dc0 Add more documents for AR connection_adapters abstract schema_definitions. [ci skip]
- Add example to column_exists?
- Add example to index_exists?
- Add document for foreign_key
- Add document for foreign_key_exists?
2015-03-03 09:28:54 +08:00
Carlos Antonio da Silva
0132a39260 Revert "delete unused method"
This reverts commit a38732c8e6ab76ea0db4e1a617a1fa84b53a9750.

Since the mutation logic was reverted in
07278519bb6db5579171fea70bccdfee1306f1d4, we must bring the reader
method back as well, since the implementation relies on it.
2015-03-02 19:14:28 -03:00
Rafael Mendonça França
90387e3e6d Merge pull request #19177 from gregmolnar/fixtures
Added testcase for #18742
2015-03-02 18:46:21 -03:00
Aaron Patterson
07278519bb Revert "mutate the transaction object to reflect state"
This reverts commit 393e65b4170608593ad82377a9eadc918e85698d and
ec51c3fedd16b561d096dcc1a6705fdc02ab7666

We don't want the records to hold hard references to transactions
because they point at records that have callbacks.
2015-03-02 11:55:18 -08:00
Aaron Patterson
a38732c8e6 delete unused method 2015-03-02 09:33:30 -08:00
Aaron Patterson
393e65b417 mutate the transaction object to reflect state
this lets us keep singleton instances of "state" values and precalculate
return values of things like `finalized?` and `completed?`.
2015-03-02 09:17:03 -08:00
Aaron Patterson
ec51c3fedd ask the txn for it's state, not a state object
this way we don't have to mutate a state object, we can just change the
state of the txn
2015-03-02 09:17:03 -08:00
Aaron Patterson
7be50103d5 change if! to unless 2015-03-02 09:17:02 -08:00
Sean Griffin
e20dc1b313 Merge pull request #19105 from amatsuda/array_take
Preserve Array#take(n) behaviour of HasManyAssociation
2015-03-02 09:38:27 -07:00