Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
#<;ActiveRecord::StatementInvalid:SQLite3::SQLException:没有这样的列:users.sender\u id:_Sql_Ruby On Rails_Database_Activerecord - Fatal编程技术网

#<;ActiveRecord::StatementInvalid:SQLite3::SQLException:没有这样的列:users.sender\u id:

#<;ActiveRecord::StatementInvalid:SQLite3::SQLException:没有这样的列:users.sender\u id:,sql,ruby-on-rails,database,activerecord,Sql,Ruby On Rails,Database,Activerecord,我正在rails应用程序中构建三个模型。一个模型引用同一个模型两次,如我的中所示。唯一的问题是,当我发出POST请求在发货表中创建新记录时。我得到这个错误: 您不想将所属的上的主键更改为关联:这是另一个表的ID列(ID) 相反,您希望: belongs_to :sender, class_name: "User", foreign_key: "sender_id" belongs_to :receiver, class_name: "User", foreign_key: "receiver_

我正在rails应用程序中构建三个模型。一个模型引用同一个模型两次,如我的中所示。唯一的问题是,当我发出POST请求在发货表中创建新记录时。我得到这个错误:


您不想将
所属的
上的
主键更改为
关联:这是另一个表的ID列(
ID

相反,您希望:

belongs_to :sender, class_name: "User", foreign_key: "sender_id"
belongs_to :receiver, class_name: "User", foreign_key: "receiver_id"
。。。这是默认值,因此这也应该起作用:

belongs_to :sender, class_name: "User"
belongs_to :receiver, class_name: "User"