jackc / surus

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

PG::SyntaxError: ERROR: syntax error at or near ")" #15

Closed simonwh closed 6 years ago

simonwh commented 9 years ago

Hi,

I'm having some issues with including has_many :through relations.

This works fine (volunteer belongs_to user)

Volunteer.all_json(include: { user: { columns: [:fullname] }})

This does not work (volunteer has_many teams through members_teams)

Volunteer.all_json(include: { teams: { columns: [:id] }})
PG::SyntaxError: ERROR: syntax error at or near ")" LINE 1: ...count", "volunteers"."accepted_timeslots_terms", () "teams" ... ^ :
select array_to_json(coalesce(array_agg(row_to_json(t)), '{}')) from (SELECT "volunteers"."id", "volunteers"."user_id", "volunteers"."festival_id", "volunteers"."tshirt", [more volunteer attributes], "volunteers"."teams_count", "volunteers"."accepted_timeslots_terms", () "teams" FROM "volunteers") t

Any clues?

Thanks a lot :-)

jackc commented 9 years ago

Unfortunately, Surus can't build JSON queries for has_many :through relations yet. I don't think it will be that hard, but I just haven't invested the time yet.