【发布时间】:2015-08-17 22:04:21
【问题描述】:
我有公司模型和模型 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: no such column: sent_invitations.confrm: SELECT "companies".* FROM "companies" INNER JOIN "invintations" ON "invintations"."sender_id" = "companies"."id " WHERE "sent_invitations"."confrm" = 't'
我知道这种方式只显示发送邀请的公司,这是必要的,包括邀请
【问题讨论】:
-
你的
schema.rb呢?你有这些模型的迁移吗? -
该列是否存在?您是否运行了所有迁移?此外,“invintations”拼写错误——帮自己一个忙,现在就改正它。
-
create_table "invintations", force: true do |t| t.integer "sender_id" t.integer "recipient_id" t.integer "author_id" t.boolean "confirm",默认:false t.datetime "created_at" t.datetime "updated_at" end
-
是的,所有迁移都运行了
标签: ruby-on-rails ruby-on-rails-4