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 commit3ea8403554
, reversing changes made toe4cde5d58c
. 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:
parent
c507f9f4c9
commit
a2075f4142
3 changed files with 6 additions and 21 deletions
|
@ -533,22 +533,6 @@
|
|||
|
||||
*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.
|
||||
|
||||
Previously, executing an insert SQL in `PostgreSQL` with a command like this:
|
||||
|
|
|
@ -995,8 +995,6 @@ module ActiveRecord
|
|||
columns_hash.key?(field.to_s) ? arel_table[field] : field
|
||||
end
|
||||
arel.project(*expanded_select)
|
||||
elsif from_value
|
||||
arel.project(Arel.star)
|
||||
else
|
||||
arel.project(@klass.arel_table[Arel.star])
|
||||
end
|
||||
|
|
|
@ -151,10 +151,13 @@ class RelationTest < ActiveRecord::TestCase
|
|||
assert_equal relation.to_a, Comment.select('a.*').from(relation, :a).to_a
|
||||
end
|
||||
|
||||
def test_finding_with_subquery_without_select
|
||||
relation = Topic.where(:approved => true)
|
||||
assert_equal relation.to_a, Topic.from(relation).to_a
|
||||
def test_finding_with_subquery_without_select_does_not_change_the_select
|
||||
relation = Topic.where(approved: true)
|
||||
assert_raises(ActiveRecord::StatementInvalid) do
|
||||
Topic.from(relation).to_a
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_finding_with_conditions
|
||||
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
|
||||
|
|
Loading…
Reference in a new issue