关系 has_many/belongs_to PG::UndefinedColumn
Relation has_many/belongs_to PG::UndefinedColumn
我在执行此操作时遇到此错误:
user.owned_tipsters
错误:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERREUR: column tipsters.user_id does not exist
我的代码:
class User < ActiveRecord::Base
has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner
end
class Tipster < ActiveRecord::Base
belongs_to :owner, class_name: 'User', inverse_of: :owned_tipsters
end
如果你能帮我知道这个错误在哪里,我会感谢你
鲍里斯
谢谢
在你里面加foreign_keyuser.rb
class User < ActiveRecord::Base
has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner, foreign_key: 'owner_id'
end
我在执行此操作时遇到此错误:
user.owned_tipsters
错误:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERREUR: column tipsters.user_id does not exist
我的代码:
class User < ActiveRecord::Base
has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner
end
class Tipster < ActiveRecord::Base
belongs_to :owner, class_name: 'User', inverse_of: :owned_tipsters
end
如果你能帮我知道这个错误在哪里,我会感谢你
鲍里斯 谢谢
在你里面加foreign_keyuser.rb
class User < ActiveRecord::Base
has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner, foreign_key: 'owner_id'
end