Commit Graph

49329 Commits

Author SHA1 Message Date
Sean Griffin
320600c773 Remove all references to where_values in association code 2015-01-25 16:46:54 -07:00
Sean Griffin
87726b93d4 Remove references to :bind in except
Bind values are no longer a thing, so this is unnecessary.
2015-01-25 16:40:23 -07:00
Sean Griffin
def2879d7d Move where merging logic over to WhereClause
This object being a black box, it knows the details of how to merge
itself with another where clause. This removes all references to where
values or bind values in `Relation::Merger`
2015-01-25 16:31:21 -07:00
Sean Griffin
2c46d6db4f Introduce Relation::WhereClause
The way that bind values are currently stored on Relation is a mess.
They can come from `having`, `where`, or `join`. I'm almost certain that
`having` is actually broken, and calling `where` followed by `having`
followed by `where` will completely scramble the binds.

Joins don't actually add the bind parameters to the relation itself, but
instead add it onto an accessor on the arel AST which is undocumented,
and unused in Arel itself. This means that the bind values must always
be accessed as `relation.arel.bind_values + relation.bind_values`.
Anything that doesn't is likely broken (and tons of bugs have come up
for exactly that reason)

The result is that everything dealing with `Relation` instances has to
know far too much about the internals. The binds are split, combined,
and re-stored in non-obvious ways that makes it difficult to change
anything about the internal representation of `bind_values`, and is
extremely prone to bugs.

So the goal is to move a lot of logic off of `Relation`, and into
separate objects. This is not the same as what is currently done with
`JoinDependency`, as `Relation` knows far too much about its internals,
and vice versa. Instead these objects need to be black boxes that can
have their implementations swapped easily.

The end result will be two classes, `WhereClause` and `JoinClause`
(`having` will just re-use `WhereClause`), and there will be a single
method to access the bind values of a `Relation` which will be
implemented as

```
join_clause.binds + where_clause.binds + having_clause.binds
```

This is the first step towards that refactoring, with the internal
representation of where changed, and an intermediate representation of
`where_values` and `bind_values` to let the refactoring take small
steps. These will be removed shortly.
2015-01-25 16:23:01 -07:00
Sean Griffin
79f71d35e9 Don't access the where values hash directly in through associations
See 4d7a62293e148604045a5f78a9d4312e79e90d13 for the reasoning
2015-01-25 16:13:27 -07:00
Sean Griffin
4d7a62293e Don't rely as much on the structure of the values hash in associations
The structure of `values[:where]` is going to change, with an
intermediate definition of `where_values` to aid the refactoring.
Accessing `values[:where]` directly messes with that, signficantly.

The array wrapping is no longer necessary, since `where_values` will
always return an array.
2015-01-25 16:11:07 -07:00
Zachary Scott
ffd495cf21 Merge pull request #18683 from cllns/fix-typo-in-migration-generator-comment
Fix typos in migration generator comment
2015-01-25 13:32:54 -08:00
Sean Collins
73c788dddf Fix typo 'has' => 'have' 2015-01-25 16:24:14 -05:00
Sean Collins
be2a373326 Fix typo 'another frameworks' => 'other frameworks' 2015-01-25 16:20:42 -05:00
Robin Dupret
77cb58ba90 Merge pull request #18681 from rymai/patch-1
Fix a typo "devleopment" => "development"
2015-01-25 16:10:01 +01:00
Rémy Coutable
cb18c07f6d Fix a typo "devleopment" => "development"
[ci skip]
2015-01-25 16:07:54 +01:00
Yves Senn
862c8c65a3 Merge pull request #18680 from y-yagi/tmp_sessions
fix task description for tmp:create
2015-01-25 15:25:45 +01:00
yuuji.yaginuma
9e99bb512d fix task description for tmp:create 2015-01-25 21:25:35 +09:00
Yves Senn
9373ca2808 remove trailing whitespace. [ci skip] 2015-01-25 12:16:32 +01:00
Yves Senn
f6996bf586 Merge pull request #18678 from bryanbibat/windows_binstubs
Add tip for running binstubs on Windows [ci skip]
2015-01-25 10:19:18 +01:00
Abdelkader Boudih
921915cd95 Merge pull request #18677 from yachibit/docs_for_datetime_select
Add missing options to `datetime_select` [ci skip]
2015-01-25 07:11:41 +00:00
Bryan Bibat
eed34e2251 Add tip for running binstubs on Windows [ci skip]
The default command prompt under Windows doesn't run binstubs correctly
while PowerShell needs to find the location of the Ruby interpreter for
it to work properly. Passing the binstubs manually to the interpreter
solves this problem.
2015-01-25 14:18:07 +08:00
yachibit
d8bf32231e Add missing options to datetime_select [ci skip] 2015-01-25 14:30:03 +09:00
Sean Griffin
3327cd3f61 Expand the number of types which can use prepared statements
This will allow all types which require no additional handling to use
prepared statements. Specifically, this will allow for `true`, `false`,
`Date`, `Time`, and any custom PG type to use prepared statements. This
also revealed another source of nil columns in bind params, and an
inconsistency in their use.

The specific inconsistency comes from a nested query coming from a
through association, where one of the inversed associations is not
bi-directional.

The stop-gap is to simply construct the column at the site it is being
used. This should simply go away on its own once we use `Attribute` to
represent them instead, since we already have all of the information we
need.
2015-01-24 21:07:55 -07:00
Sean Griffin
ae8cd56c7b Don't mutate where_values
This is to help facilitate future refactorings, as the internal
representation is changed. I'm planning on having `where_values` return
an array that's computed on call, which means that mutation will have no
affect. This is the only remaining place that was mutating (tested by
replacing the method with calling `dup`)
2015-01-24 20:02:46 -07:00
Sean Griffin
c80487eb1a Don't rely on relation mutability when building through associations
Specifically, the issue is relying on `where_unscoping` mutating the
where values. It does not, however, mutate the bind values, which could
cause an error under certain circumstances. This was not exposed by the
tests, since the only place which would have been affected is unscoping
a boolean, which doesn't go through prepared statements. I had a hard
time getting better test coverage to demonstrate the issue.

This in turn, caused `merge` to go through proper logic, and try to
clear out the binds associated with the unscoped relation, which then
exposed a source of `nil` for the columns, as binds weren't expanding
`{ "posts.id" => 1 }` to `{ "posts" => { "id" => 1 } }`. This has been
fixed.

The bulk of `create_binds` needed to be moved to a separate method,
since the dot notation should not be expanded recursively.

I'm pretty sure this removes a subtle quirk that a ton of code in
`Relation::Merger` is working around, and I suspect that code can be
greatly simplified. However, unraveling that rats nest is no small task.
2015-01-24 19:51:26 -07:00
Sean Griffin
4c0a9922d6 Don't duplicate Relation::VALUE_METHODS in Relation::Merger 2015-01-24 18:49:49 -07:00
Xavier Noria
01849a9749 Merge pull request #18671 from yui-knk/fix/const_guide
[ci skip] Fix what is pushed to nesting about eval family
2015-01-24 15:34:22 +01:00
Yves Senn
c8e39e2fd4 Merge pull request #18670 from morgoth/fix-duplicating-errors-details
Fixed duplicating ActiveModel::Errors#details
2015-01-24 15:08:11 +01:00
yui-knk
419d259f63 [ci skip] Fix what is pushed to nesting about eval family 2015-01-24 22:50:08 +09:00
Sean Griffin
9bf9097973 Merge pull request #18663 from egilburg/reuse-attribute-assignment
Use attribute assignment module logic during ActiveModel initialization.
2015-01-24 06:38:23 -07:00
Wojciech Wnętrzak
fb7d95b212 Fixed duplicating ActiveModel::Errors#details 2015-01-24 11:58:55 +01:00
Sean Griffin
847395a04d Merge pull request #18474 from notEthan/pretty_print_inspect
pretty_print will use #inspect if a subclass redefines it
2015-01-23 16:25:15 -07:00
Sean Griffin
7a69e27cde Fix test failure on PG caused by 7c6f3938dee47f093 2015-01-23 16:16:16 -07:00
Eugene Gilburg
5bdb42159e use attribute assignment module logic during active model initialization 2015-01-23 14:42:47 -08:00
Sean Griffin
8c83bd0732 Merge pull request #10776 from bogdan/assign-attributes
Extracted attributes assingment from ActiveRecord to ActiveModel
2015-01-23 14:54:33 -07:00
Sean Griffin
a225d4bec5 ✂️ and 💅 for #10776
Minor style changes across the board. Changed an alias to an explicit
method declaration, since the alias will not be documented otherwise.
2015-01-23 14:51:59 -07:00
Bogdan Gusiev
2606fb3397 Extracted ActiveRecord::AttributeAssignment to ActiveModel::AttributesAssignment
Allows to use it for any object as an includable module.
2015-01-23 23:43:22 +02:00
Sean Griffin
7c6f3938de Move integer range validation to never raise on assignment
Given that this was originally added to normalize an error that would
have otherwise come from the database (inconsistently), it's more
natural for us to raise in `type_cast_for_database`, rather than
`type_cast_from_user`. This way, things like numericality validators can
handle it instead if the user chooses to do so. It also fixes an issue
where assigning an out of range value would make it impossible to assign
a new value later.

This fixes several vague issues, none of which were ever directly
reported, so I have no issue number to give. Places it was mentioned
which I can remember:

- 9ba21381d7/lib/shoulda/matchers/active_model/allow_value_matcher.rb (L261-L263)
- https://github.com/rails/rails/issues/18653#issuecomment-71197026
2015-01-23 14:30:23 -07:00
Sean Griffin
96e504ec8a Errors raised in type_cast_for_database no longer raise on assignment
Fixes #18580.
2015-01-23 12:50:01 -07:00
Sean Griffin
b9d668f8cb Don't remove join dependencies in Relation#exists?
Fixes #18632
2015-01-23 12:05:14 -07:00
Rafael Mendonça França
2698e18757 Merge pull request #18651 from mechanicles/use-public-send
Use 'public_send' over the 'send' method for object's properties and public methods.
2015-01-23 11:53:14 -02:00
Xavier Noria
4e02dcc252 constants guide: make assumption explicit in an example [closes #18465] [ci skip] 2015-01-23 11:21:42 +01:00
Santosh Wadghule
b15a47deff Use 'public_send' over the 'send' method for object's properties. 2015-01-23 11:08:50 +05:30
Rafael Mendonça França
139c232b07 Merge pull request #18643 from kaspth/renderer-normalize_keys-speedup
Speed up ActionController::Renderer `normalize_keys` by ~28%.
2015-01-22 15:22:18 -02:00
Zachary Scott
2ced07de4f Merge pull request #18644 from rwarbelow/fix-wording-of-css-manifest
fix wording of CSS manifest instructions [ci skip]
2015-01-22 09:21:55 -08:00
Rachel Warbelow
285224e2ae fix wording of CSS manifest instructions 2015-01-22 09:57:21 -07:00
Kasper Timm Hansen
d3211d76ce Speed up normalize_keys by removing dup step.
Previously env was duplicated and then had it's keys mutated. This iterates through
the hash twice.
Using `transform_keys`, duplication and key mutation is a single iteration.

`convert_symbols` was renamed to `http_header_format`.
2015-01-22 17:35:19 +01:00
Rafael Mendonça França
3d4eaf6dad Merge pull request #18641 from splattael/disable-ar-jdbc-master
Disable builds AR-JDBC against master
2015-01-22 13:50:17 -02:00
Abdelkader Boudih
fd6c8b6f34 Merge pull request #18642 from y-yagi/active_record_validations_guide
fix regexp for validate an integer in guides [ci skip]
2015-01-22 14:38:18 +00:00
Rafael Mendonça França
4b6449f84d Merge pull request #18636 from josh/railties-remove-config-assets
Remove config.assets
2015-01-22 12:18:06 -02:00
Rafael Mendonça França
e36ecf4d77 Merge pull request #18546 from brainopia/action_view_render
A shortcut to setup controller environment
2015-01-22 12:09:32 -02:00
yuuji.yaginuma
fce9c4e5e1 fix regexp for validate an integer in guides [ci skip] 2015-01-22 22:56:41 +09:00
Peter Suschlik
49585be858 Disable builds AR-JDBC against master
Currently, bundling `activerecord-jdbc-adapter`'s master branch seems to
be broken. See jruby/activerecord-jdbc-adapter#614

This commit partially reverts #12107
2015-01-22 12:35:03 +01:00
Yves Senn
9d519eefbc Merge pull request #18635 from BenMorganIO/use-two-spaces-instead-of-one-for-wrap-params
use two spaces instead of one for include root in json
2015-01-22 08:11:33 +01:00