提问人:Kubatron P 提问时间:9/28/2023 最后编辑:Kubatron P 更新时间:9/28/2023 访问量:30
jsonapi-resources:MySQL 错误 - 0.10.x、0.11.0.beta2、Ruby on Rails
jsonapi-resources: MySQL Error - 0.10.x, 0.11.0.beta2, Ruby on Rails
问:
Jsonapi-resources:MySQL 错误 - 0.10.x、0.11.0.beta2
- 导轨:7.0.8
- mysql2:0.5.5
- jsonapi 资源:0.10.x、0.11.0.beta2
我们尝试使用 MySQL DB 将 jsonapi-resources 实现到我们的项目中。首先,我们尝试了文档中的演示(https://jsonapi-resources.com/v0.10/guide/basic_usage.html)示例,并立即收到此MySQL错误:
"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",
应用程序控制器:
class ApplicationController < ActionController::Base
include JSONAPI::ActsAsResourceController
protect_from_forgery with: :null_session
end
资源:
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
模型:
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
路线:
Rails.application.routes.draw do
jsonapi_resources :contacts
jsonapi_resources :phone_numbers
end
如果我们降级到 jsonapi-resources 0.9.12,一切正常。
答: 暂无答案
评论