rails 使用复合键时出现问题

Problems in rails while using composite keys

我正在使用来自外部数据库的复合键 mysql。我添加了 composite_primary_keys gem 并且还添加了 require 'composite_primary_keys 到我的 environments.rb 文件中。

当我尝试执行显示操作时,出现以下错误。

localhost:3000/prereq_conf_expr_tbls/1,PREQ 1,1

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 
'1,1) LIMIT 1' at line 1: SELECT `PREREQ_CONF_EXPR_TBL`.* FROM 
`PREREQ_CONF_EXPR_TBL` WHERE (1,PREQ 1,1) LIMIT 1

关联表是使用这些命令创建的 mysql。

CREATE TABLE PREREQ_CONF_EXPR_TBL(CMD_ID INT, ENTRY_TYPE VARCHAR(255), 
FIELD_NO INT, EXPR_ID INT, LOGICAL_OP VARCHAR(255), PRIMARY KEY(CMD_ID, 
ENTRY_TYPE, FIELD_NO), FOREIGN KEY(EXPR_ID) REFERENCES EXPRESSION(EXPR_ID) ON 
DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY(CMD_ID) REFERENCES 
BASE_CMD_TBL(CMD_ID) ON DELETE CASCADE ON UPDATE CASCADE);

控制器

class PrereqConfExprTblsController < ApplicationController
    def index
        @prereqs = PREREQ_CONF_EXPR_TBL.all
    end

    def new
        @prereqs = PREREQ_CONF_EXPR_TBL.new
    end

    def show
        @prereqs = PREREQ_CONF_EXPR_TBL.find_by(params[:id])
    end

    def edit
        @prereqs = PREREQ_CONF_EXPR_TBL.find_by(params[:id])
    end

    def create
        @prereqs = PREREQ_CONF_EXPR_TBL.new(prereq_params)
        if @prereqs.save
            redirect_to @prereqs
        else
            render 'new'
        end
    end

    def update
        @prereqs = PREREQ_CONF_EXPR_TBL.find_by(params[:id])
        if @prereqs.update_attributes(prereq_params)
            redirect_to prereq_conf_expr_tbls_url
        else
            render 'edit'
        end
    end

    def destroy
        PREREQ_CONF_EXPR_TBL.find_by(params[:id]).destroy
        redirect_to prereq_conf_expr_tbls_url
    end

    private

        def prereq_params
            params.require(:prereq_conf_expr_tbl).permit(:CMD_ID, :ENTRY_TYPE ,:FIELD_NO ,:EXPR_ID, :LOGICAL_OP)
        end
end

型号

class PREREQ_CONF_EXPR_TBL < ExternalDbAccess
    self.table_name = "PREREQ_CONF_EXPR_TBL"
    self.primary_keys = 'CMD_ID', 'ENTRY_TYPE', 'FIELD_NO'
end

路线

resources :prereq_conf_expr_tbls

想通了。而不是使用 .find_by 使用 .find