3

In rails 3 if I write: Model.from('models') arel generates the following sql:

select "models".* from models

In rails 4 the same arel generates the following sql:

select "models".* from 'models', NULL

The table name is wrapped in quotes and ', NULL' is appended. How do I use arel to give me the same results as in rails 3?

I was leveraging the original behavior so I could run a fairly complex with recursive query against postgres. In rails4, postgres is choking when it gets to the single quote preceding value I give from.

Is there a better way to do a with recursive query? Or, is there a way to query with arel so it works as before?

Charles
  • 50,943
  • 13
  • 104
  • 142
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
  • 1
    I'm not able to duplicate that error you're seeing. Using an app with a vendors table I see the same SQL statement on both 3.2 & 4 with `Vendor.from('vendors').to_sql` which results in `#=> "SELECT \"vendors\".* FROM vendors"`. Could you share more of your complex query? – Dan Reedy Jul 18 '13 at 16:12
  • Hmm, I'm not even using the complex query at this point, just a simple query like the one you tried. Still, I'm getting a different `to_sql`. Maybe version difference? Rails 4.0.0, pg 0.15.1. Any other relevant gems? – Dane O'Connor Jul 18 '13 at 16:17
  • @DanReedy aha! thanks for the sanity check. This is being caused by the squeel gem. Must be an incompatibility, since I get the expected behavior when I remove it from my project. I'll take it up with them. – Dane O'Connor Jul 18 '13 at 16:26

1 Answers1

1

This appears to be an incompatibility with the squeel gem (the master branch as of today).

EDIT I've sent a pull request to squeel's master branch. Fixes the issue for me.

EDIT 2: Merged into master

Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173