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

Revert "Merge pull request #13344 from ccutrer/fix-from-default-select"

This reverts commit 3ea8403554, reversing
changes made to e4cde5d58c.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/query_methods.rb

Reason: using `from` without `select` should not change the select list
to SELECT * because it can lead different query results. If it is needed
to change the table to a subquery or a view you can pass a table alias
in the `from` call or use `select('subquery.*')`.

Fixes #14049.
This commit is contained in:
Rafael Mendonça França 2014-02-17 10:49:38 -03:00
parent c507f9f4c9
commit a2075f4142
3 changed files with 6 additions and 21 deletions

View file

@ -533,22 +533,6 @@
*Damien Mathieu* *Damien Mathieu*
* Improve the default select when `from` is used.
Previously, if you did something like Topic.from(:temp_topics), it
would generate SQL like:
SELECT topics.* FROM temp_topics;
Which is will cause an error since there's not a topics table to select
from.
Now the default if you use from is just `*`:
SELECT * FROM temp_topics;
*Cody Cutrer*
* Fix `PostgreSQL` insert to properly extract table name from multiline string SQL. * Fix `PostgreSQL` insert to properly extract table name from multiline string SQL.
Previously, executing an insert SQL in `PostgreSQL` with a command like this: Previously, executing an insert SQL in `PostgreSQL` with a command like this:

View file

@ -995,8 +995,6 @@ module ActiveRecord
columns_hash.key?(field.to_s) ? arel_table[field] : field columns_hash.key?(field.to_s) ? arel_table[field] : field
end end
arel.project(*expanded_select) arel.project(*expanded_select)
elsif from_value
arel.project(Arel.star)
else else
arel.project(@klass.arel_table[Arel.star]) arel.project(@klass.arel_table[Arel.star])
end end

View file

@ -151,11 +151,14 @@ class RelationTest < ActiveRecord::TestCase
assert_equal relation.to_a, Comment.select('a.*').from(relation, :a).to_a assert_equal relation.to_a, Comment.select('a.*').from(relation, :a).to_a
end end
def test_finding_with_subquery_without_select def test_finding_with_subquery_without_select_does_not_change_the_select
relation = Topic.where(:approved => true) relation = Topic.where(approved: true)
assert_equal relation.to_a, Topic.from(relation).to_a assert_raises(ActiveRecord::StatementInvalid) do
Topic.from(relation).to_a
end
end end
def test_finding_with_conditions def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name) assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name) assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)