Skip to content

Multi-tenancy SQL syntax error caused by ActiveRelationResource (0.10.x) #1310

@Albertjan90

Description

@Albertjan90

This issue is a (choose one):

  • Problem/bug report.

Checklist before submitting:

  • I've searched for an existing issue.

Description

After upgrading JSONAPI::Resources to version 0.10.2 (coming from 0.9), we noticed the API is causing SQL errors when loading resources from a different database. We have a multi-tenant database, so some resources are fetched from a shared database. It seems this line is causing the syntax to break:
https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/active_relation_resource.rb#L117

Fetching resources from a different database results in the given query:

SELECT database.table.id AS database.table_id (...)

The dot (.) in the alias is illegal. This results in the following error:

Internal Server Error: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.table_id ' at line 1: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions