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

to_sql does not work as intended when as is used. #18675

Closed
fdeschenes opened this issue Jan 24, 2015 · 1 comment
Closed

to_sql does not work as intended when as is used. #18675

fdeschenes opened this issue Jan 24, 2015 · 1 comment

Comments

@fdeschenes
Copy link

Without as, works as intended

2.1.0 :001 > Post.where(id: 2).to_sql
 => "SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"id\" = 2" 

With as, does not work as intended

2.1.0 :001 > Post.where(id: 2).as('post').to_sql
 => "(SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"id\" = $1) post" 

I expect the returned value to be "(SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"id\" = 2) post"

@matthewd
Copy link
Member

See #18379; you're (maybe unknowingly) using an Arel method; its return value has some similar methods to AR::Relation, including to_sql... but it's not the same.

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

No branches or pull requests

2 participants