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

SQL where clauses are not kept in the order they are called if using raw wheres #459

Closed
matthewmcgarvey opened this issue Sep 11, 2020 · 0 comments · Fixed by #460
Closed

Comments

@matthewmcgarvey
Copy link
Member

Failing spec:

it "keeps the sql in order that it was called when raw where methods used with non-raw" do
  query = UserQuery.new.where("first_name = ?", "Paul").name("Smith").query

  query.statement.should eq "SELECT #{User::COLUMN_SQL} FROM users WHERE first_name = 'Paul' AND users.name = $1"
  query.args.should eq ["Smith"]
end

Failure message:

Failure/Error: query.statement.should eq "SELECT #{User::COLUMN_SQL} FROM users WHERE first_name = 'Paul' AND users.name = $1"

       Expected: "SELECT users.id, users.created_at, users.updated_at, users.name, users.age, users.year_born, users.nickname, users.joined_at, users.total_score, users.average_score, users.available_for_hire FROM users WHERE first_name = 'Paul' AND users.name = $1"
            got: "SELECT users.id, users.created_at, users.updated_at, users.name, users.age, users.year_born, users.nickname, users.joined_at, users.total_score, users.average_score, users.available_for_hire FROM users WHERE users.name = $1 AND first_name = 'Paul'"

Raw wheres are currently stored separately from the regular where clauses (source). The raw wheres are appended to the end where statement when make the full sql string. This is fine when our api only supports AND statements but is a problem when OR is added to the API.

Potential Solutions

  • Do not allow further "where" methods if a raw where method is used
  • Unify the where and raw where list so that the order is preserved
  • ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant