jackc / surus

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

Handle has_one association #14

Closed Madumo closed 9 years ago

Madumo commented 9 years ago

Hi,

First of all, great gem, its really awesome. Some of my queries that was taking 3800ms are now taking only 70ms to render with the all_json method!

I just had one problem with it. The has_one association was not handled so it generated queries with empty subqueries, which crashed:

select row_to_json(t) from (SELECT "users"."id", "users"."name", "users"."email", () "bio" FROM "users" WHERE "users"."id" = 39) t

I fixed it by simply using the HasManyScopeBuilder but returning a RowQuery instead of an ArrayAggQuery. I also added some specs.

If something is wrong, just tell me and I will fix it. Have a good day!

jackc commented 9 years ago

Thanks! Good idea.