为什么我收到错误没有这样的列?

时间:2015-08-17 13:59:01

标签: ruby-on-rails ruby-on-rails-4

我有公司模型和模型Invintaton,公司可以邀请其他公司进行消息传递,现在我只需要展示确认消息传递的公司

class Company < ActiveRecord::Base
  has_many :sent_invitations, class_name: 'Invintation', foreign_key: 'sender_id'
  has_many :invitation_recipients, through: :sent_invitations, source: :recipient 
  has_many :incoming_invitations, class_name: 'Invintation', foreign_key: 'recipient_id'
  has_many :invitation_senders, through: :incoming_invitations, source: :sender
end 

class Invintation < ActiveRecord::Base
  belongs_to :recipient, class_name: 'Company', foreign_key: 'recipient_id'
  belongs_to :sender, class_name: 'Company', foreign_key: 'sender_id'
end

class MessagesController < ApplicationController


  def new
    @company = Company.find(params[:company_id])
    @message = @company.sent_messages.new
    @recipients = Company.joins(:invitation_recipients).where(invitation_recipients: {sender_id: @company.id, confrm: true})
  end
end

但我收到错误SQLite3 :: SQLException:没有这样的列:sent_invitations.confrm:SELECT&#34;公司&#34;。* FROM&#34;公司&#34; INNER JOIN&#34; invintations&#34; ON&#34; invintations&#34;。&#34; sender_id&#34; =&#34;公司&#34;。&#34; id&#34;在哪里&#34; sent_invitations&#34;。&#34; confrm&#34; =&#39; t&#39;

我知道这种方式只显示发送邀请的公司,这是必要的,并包含邀请

1 个答案:

答案 0 :(得分:0)

您的查询中至少有两个拼写错误:

  • sent_invitations.confrm,但应该是sent_invitations.confirm
  • Invintation,但应该是Invitation

检查您的代码并修复拼写错误,假设未生成具有相同拼写错误的数据库架构。