jackc / surus

PostgreSQL extensions for ActiveRecord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

find_json and all_json fail when using AR joins

dparis opened this issue · comments

When running an AR query like:

Post.joins(:author).all_json

or

Post.joins(:author).find_json(1)

Postgres returns an error about an ambiguous reference to the id field. This stems from how the subquery_sql method builds the subquery using columns.map(...) here: https://github.com/JackC/surus/blob/master/lib/surus/json/query.rb#L17

Are there any clever ways to form the AR query to remove the ambiguity, or does subquery_sql just need to be made less naive about the column names? Seems like that module class should have enough info to just prepend the table name to each column entry when building the subquery. Barring any additional join-related query functionality, that seems like it should be enough to make these two methods behave as expected.

Cheers!

Fixed in 362a204 for master and ec829d1 for rails3 branch.

Thanks for the fix. 😄

Has the rails3 branch been updated on rubygems?

Not yet. You'll have to point your Gemfile at github for now.