Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure order quote symbol arguments #12718

Closed
wants to merge 2 commits into from

Conversation

timfjord
Copy link
Contributor

Current order implementation contains symbol parsing and converting it to Arel::Nodes::Ordering
But this code will be never executed, because we preprocess symbol params and convert it to Arel::Nodes::Ascending.
But when we convert it to Arel::Nodes::Ascending it has issues with some values(for example :key, see here #2601)

So i removed symbol preprocessing and leave all calculation on build_order method

Also this pull fixes limited_ids_for method for postgresql adapter, which is passing order_values(raw values that we pass to order) to columns_for_distinct. So for symbol(after i removed preprocessing) and hash arguments it will raise NoMethodError, because there is no to_sql method

@@ -35,15 +35,7 @@ def relation
assert relation.order!('name ASC').equal?(relation)
assert_equal ['name ASC'], relation.order_values
end

test '#order! with symbol prepends the table name' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the test was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because they were very specific to implementation.
After we remove preprocessing, order_values will contain raw data, so there are no ascending?, expr.name and expr.relation.name.
I tried swap node = relation.order_values.first with node = relation.arel.orders.first, but it raises error.
So i decided remove those specs for now.
Please let me know if i need bring them back and adapt to current implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also add specs here to cover hash arguments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Yes, we will need some integration tests to make sure the behavior was ne regressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I will work on tests.

@timfjord
Copy link
Contributor Author

@rafaelfranca i added tests

@senny
Copy link
Member

senny commented Feb 3, 2014

@Timsly is this PR still required? I tried to reproduce the error case with :key but had no success:

  def test_order_by_key
    Post.create(key: "b")
    Post.create(key: "c")
    Post.create(key: "a")
    assert_equal ["a", "b", "c"], Post.order(:key).to_a.map(&:key)
  end

I create a gist of the complete example.

@Timsly Let me know if I'm missing something or if we can close this PR.

@senny
Copy link
Member

senny commented Mar 8, 2014

It's been a month without feedback. I'm going to close this PR. If the requested change is still necessary please report back so we can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants