1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

13 commits

Author SHA1 Message Date
Sean Griffin
bdc5141652 Move the from bind logic to a FromClause class
Contrary to my previous commit message, it wasn't overkill, and led to
much cleaner code.

[Sean Griffin & anthonynavarre]
2015-01-26 16:36:14 -07:00
Sean Griffin
8436e2c2bd Remove Relation#bind_values=
The last place that was assigning it was when `from` is called with a
relation to use as a subquery. The implementation was actually
completely broken, and would break if you called `from` more than once,
or if you called it on a relation, which also had its own join clause,
as the bind values would get completely scrambled. The simplest solution
was to just move it into its own array, since creating a `FromClause`
class for this would be overkill.
2015-01-26 16:20:58 -07:00
Sean Griffin
17b1b5d773 Remove all references to where_values in tests 2015-01-25 17:50:19 -07:00
Sean Griffin
35362817b1 Fix new warning in ruby 2.2 2014-12-26 15:13:08 -07:00
Sean Griffin
1d6bb77636 Inject the PredicateBuilder into the Relation instance
Construction of relations can be a hotspot, we don't want to create one
of these in the constructor. This also allows us to do more expensive
things in the predicate builder's constructor, since it's created once
per AR::Base subclass
2014-12-26 13:53:56 -07:00
Yves Senn
16868b53f9 A NullRelation should represent nothing. Closes #15176.
[Matthew Draper & Yves Senn]

Closes #16860. (pull request to discuss the implementation)
2014-09-11 08:04:48 +02:00
Earl J St Sauver
70b377f464 select! renamed to avoid name collision Array#select!
Fixes #14752

Select mimics the block interface of arrays, but does not mock the
block interface for select!. This change moves the api to be a
private method, _select!.
2014-04-21 14:42:59 -07:00
Lauro Caetano
6c311e0b75 Build the reverse_order on its proper method.
The reverse_order method was using a flag to control if the order should
be reversed or not. Instead of using this variable just build the reverse order
inside its proper method.

This implementation was leading to an unexpected behavior when using
reverse_order and then applying reorder(nil).

Example:
  Before
    Post.order(:name).reverse_order.reorder(nil)
    # => SELECT "posts".* FROM "posts"   ORDER BY "posts"."id" DESC

  After
    Post.order(:name).reverse_order.reorder(nil)
   # => SELECT "posts".* FROM "posts"
2014-04-07 16:23:34 -03:00
Tsutomu Kuroda
c1d9934447 Handle aliased attributes in AR::Relation#select, #order, etc.
With this we can write `Model#select(:aliased)`, `Model#order(:aliased)`,
`Model#reoder(aliased: :desc)`, etc.

Supplementary work to 54122067ac.
2014-01-29 09:16:46 +09:00
Jon Leighton
64b9e93bb5 Fix ActiveRecord::Relation#unscope
I'm pretty confused about the addition of this method. The documentation
says that it was intended to allow the removal of values from the
default scope (in contrast to #except). However it behaves exactly the
same as except: https://gist.github.com/jonleighton/7537008 (other than
having a slightly enhanced syntax).

The removal of the default scope is allowed by
94924dc32b, which was not a change we
could make until 4.1 due to the need to deprecate things. However after
that change #unscope still gives us nothing that #except doesn't already
give us.

However there *is* a desire to be able to unscope stuff in a way that
persists across merges, which would allow associations to be defined
which unscope stuff from the default scope of the associated model. E.g.

  has_many :comments, -> { unscope where: :trashed }

So that's what this change implements. I've also corrected the
documentation. I removed the guide references to #except as I think
unscope really supercedes #except now.

While we're here, there's also a potential desire to be able to write
this:

  has_many :comments, -> { unscoped }

However, it doesn't make sense and would not be straightforward to
implement. While with #unscope we're specifying exactly what we want to
be removed from the relation, with "unscoped" we're just saying that we
want it to not have some things which were added earlier on by the
default scope. However in the case of an association, we surely don't
want *all* conditions to be removed, otherwise the above would just
become "SELECT * FROM comments" with no foreign key constraint.

To make the above work, we'd have to somehow tag the relation values
which get added when evaluating the default scope in order to
differentiate them from other relation values. Which is way too much
complexity and therefore not worth it when most use cases can be
satisfied with unscope.

Closes #10643, #11061.
2013-11-20 22:23:16 +00:00
Yves Senn
f83c9b10b4 use arel nodes to represent non-string order_values.
This fixes a bug when merging relations of different classes.

```
Given:
  Post.joins(:author).merge(Author.order(name: :desc)).to_sql

Before:
 SELECT "posts".* FROM "posts"
   INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
   ORDER BY "posts"."name" DESC

After:
 SELECT "posts".* FROM "posts"
   INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
   ORDER BY "authors"."name" DESC
```
2013-11-19 17:40:21 +01:00
Rafael Mendonça França
defdeed2fc Merge pull request #12129 from Empact/deprecate-array-bang-delegation
Deprecate the delegation of Array bang methods in ActiveRecord::Delegation

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/relation_test.rb
2013-09-12 21:36:00 -03:00
Ben Woosley
5e41cb4a1e Pull the RelationMutationTests from cases/relation_test to cases/relation/mutation_test. 2013-09-03 21:03:26 -07:00