-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PG::SyntaxError with Apartment gem #1316
Comments
Just noticed this is the same issue reported 20 days ago by Albertjan90: #1310 But no one replied to his report. |
Besides the SELECT public.accounts.id AS public.accounts_id FROM "public"."accounts" WHERE "public"."accounts" = $1 The proper query should be: SELECT public.accounts.id AS accounts_id FROM public.accounts WHERE public.accounts.id = $1 |
I've got a solution by modifying the def _table_name
@_table_name ||= _model_class.respond_to?(:table_name) ? _model_class.table_name.partition('.').last : _model_name.tableize
end
Works well with and without schema for me, but this solution would probably truncate table names if they include a 'dot' (apparently that's allowed in SQL...). Haven't tested the later scenario though. |
@cedm Could you test out the #1318 PR and add comments there? I don't have the test framework setup to handle multi tenancy, and unfortunately I'm a bit short on time at the moment to work on that. Rather than your fix using |
@lgebhardt Your PR fixed the |
Improving on my hack-ish solution with: def _table_name
@_table_name ||= _model_class.respond_to?(:table_name) ? _model_class.table_name.split('.').last : _model_name.tableize
end
|
This issue is a (choose one):
Checklist before submitting:
Description
Bug reports:
When using Apartment (multi-tenancy gem), any model that is shared among all tenants (i.e. in the 'public' schema) return an error 500 (PG::SyntaxError) when trying to query the API. This issue only happens with shared models, and not with tenant-specific models. The issue lies in the way jsonapi-resources writes its queries, e.g:
The whole query is:
SELECT public.accounts.id AS public.accounts_id FROM "public"."accounts" WHERE "public"."accounts" = $1
The bold part is the issue. There should be no dot in the AS statement.
public.accounts_id
should bepublic_accounts_id
or justaccounts_id
.This should be a trivial fix, but I just don't know where in the gem code queries are generated.
The text was updated successfully, but these errors were encountered: