jackc / surus

PostgreSQL extensions for ActiveRecord
MIT License
395 stars 35 forks source link

find_json and all_json fail when using AR joins #8

Closed dparis closed 11 years ago

dparis commented 11 years ago

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!

jackc commented 11 years ago

Fixed in 362a2044e41e1ae1eb2dbb5444ade247ca1c5baa for master and ec829d12d87326b1d9ac0e0211a7ee05e0a45d73 for rails3 branch.

dparis commented 11 years ago

Thanks for the fix. :smile:

Has the rails3 branch been updated on rubygems?

jackc commented 11 years ago

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