Ruby on rails 模型中表的主键未知
我得到了表的未知主键,我无法判断为什么会出现这种情况 我的表有主键 客户说明Ruby on rails 模型中表的主键未知,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我得到了表的未知主键,我无法判断为什么会出现这种情况 我的表有主键 客户说明 # == Schema Information # # Table name: customer_notes # # id :integer not null, primary key # title :string # company_id :integer # customer_i
# == Schema Information
#
# Table name: customer_notes
#
# id :integer not null, primary key
# title :string
# company_id :integer
# customer_id :integer not null
# user_id :integer
Customer Note Version
# == Schema Information
#
# Table name: customer_note_versions
#
# id :integer not null, primary key
# title :string
# user_id :integer
# company_id :integer
# customer_note_id :integer
#
#Foreign Keys
# fk_rails_... (customer_note_id => customer_notes.id)
has_many :customer_note_versions, dependent: :destroy
validates :title, presence: true
客户远程版本
belongs_to :customer_note
validates :title, :user_id, :customer_note_id, presence: true
客户说明
# == Schema Information
#
# Table name: customer_notes
#
# id :integer not null, primary key
# title :string
# company_id :integer
# customer_id :integer not null
# user_id :integer
Customer Note Version
# == Schema Information
#
# Table name: customer_note_versions
#
# id :integer not null, primary key
# title :string
# user_id :integer
# company_id :integer
# customer_note_id :integer
#
#Foreign Keys
# fk_rails_... (customer_note_id => customer_notes.id)
has_many :customer_note_versions, dependent: :destroy
validates :title, presence: true
我正在打电话
CustomerNote.new.customer\u note\u版本
它在测试控制台上的抛出错误
ActiveRecord::UnknownPrimaryKey:表的未知主键
模型CustomerNote中的customer_注释
要拥有
CustomerNote.customer\u note\u版本
CustomerNote应已保存在数据库中。。。。您正在使用CustomerNote.new
创建id为空的活动记录。只有在保存记录后才会填写id。id应该是自动生成的。主要问题是rspecCustomerNote。new
将创建id=>nill的记录,id将在以下情况下自动分配:saved@KunalVashist如果这是客户备注的主要问题,请共享RSpec代码。客户备注的版本应已保存在数据库中。。。。您正在使用CustomerNote.new
创建id为空的活动记录。只有在保存记录后才会填写id。id应该是自动生成的。主要问题是rspecCustomerNote。new
将创建id=>nill的记录,id将在saved@KunalVashist如果这是主要问题,请共享RSpec代码