这些是我的表:
create_table :messages do |t|
t.integer :type
t.string :text
t.datetime :sent_date
t.string :sender
t.timestamps
end
create_table :users do |t|
t.integer :phone
t.string :fullname
t.string :profile_image
t.timestamps
end
create_table :send_tos do |t|
t.string :receiver
t.belongs_to :message
t.boolean :is_received
end
这些是模型类:
class User < ActiveRecord::Base
has_many :send_tos, :foreign_key => 'receiver'
has_many :messages, :foreign_key => 'sender'
end
class Message < ActiveRecord::Base
belongs_to :user, :foreign_key => 'sender'
has_many :send_tos
end
class Send_to < ActiveRecord::Base
belongs_to :user, :foreign_key => "receiver"
belongs_to :message
end
当我在 rails 控制台上运行这些命令时:
m = Message.new
m.save
s = Send_to.new
s.message = m
s.save
m.send_tos
命令后m.send_tos
我收到此错误:
RuntimeError:自动加载常量 SendTo 时检测到循环依赖
为什么我会收到此错误?我应该怎么做才能改变它?