jsonapi-resources: MySQL Error - 0.10.x, 0.11.0.beta2, Ruby on Rails

38 views Asked by At

Jsonapi-resources: MySQL Error - 0.10.x, 0.11.0.beta2

  • Rails: 7.0.8
  • mysql2: 0.5.5
  • jsonapi-resources: 0.10.x, 0.11.0.beta2

We tried to implement jsonapi-resources into our project with MySQL DB. Firstly we tried a demo (https://jsonapi-resources.com/v0.10/guide/basic_usage.html) example from the documentation and we immediately got this MySQL error:

"exception": "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 '.\"id\" AS \"contacts_id\", `contacts`.`id` FROM `contacts` ORDER BY contacts.id asc' at line 1",

Application Controller:

class ApplicationController < ActionController::Base
  include JSONAPI::ActsAsResourceController
  protect_from_forgery with: :null_session
end

resources:

class ContactResource < JSONAPI::Resource
  attributes :name_first, :name_last, :email, :twitter
  has_many :phone_numbers
end


class PhoneNumberResource < JSONAPI::Resource
  attributes :name, :phone_number
  has_one :contact
  filter :contact
end

models:

class Contact < ApplicationRecord
  has_many :phone_numbers
  validates :name_first, presence: true
  validates :name_last, presence: true
end

class PhoneNumber < ApplicationRecord
  belongs_to :contact
end

routes:

Rails.application.routes.draw do
  jsonapi_resources :contacts
  jsonapi_resources :phone_numbers
end

If we downgrade to jsonapi-resources 0.9.12 everything works just fine.

0

There are 0 answers