Reputation: 557
I get this error when I do this:
user.owned_tipsters
Error:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERREUR: column tipsters.user_id does not exist
My code:
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
If you can help me to know where does this error, I would thank you
Boris Thx
Upvotes: 1
Views: 289
Reputation: 4615
add foreign_key in you user.rb
class User < ActiveRecord::Base
has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner, foreign_key: 'owner_id'
end
Upvotes: 2