这里是我目前的问题的一些信息:Rails 4 has_many关联两次在同一模型
我有两个模型,用户和活动。用户可以创建活动并为其添加书签。
我目前有一个工作设置,允许用户创建活动,我正在修改它也能够将它们加入书签,但没有成功。
user.rb:
class User < ActiveRecord::Base
...
has_many :activities
...
end
activity.rb
class Activity < ActiveRecord::Base
...
belongs_to :user
...
end
我可以做这样的事情?
class User < ActiveRecord::Base
has_many :activities
has_many :bookmarks, :through => :activities
end
是一个many_to_many与'inbetween'模型更合适的方法吗?
对于上述做法,当我试图检索用户的书签,这是我得到:
ActiveRecord::HasManyThroughSourceAssociationNotFoundError (Could not find the source association(s) "bookmark" or :bookmarks in model Activity.
你能形容更多吗?发生了什么,有什么错误信息? –
是的,例如,当我使用上述方法处理问题并尝试检索用户的书签时,出现此错误: “ActiveRecord :: HasManyThroughSourceAssociationNotFoundError(无法找到源关联”书签“或:书 标记在模型活动。试试'has_many:书签,:通过=>:活动,:来源=>'。“ 谢谢你的回复 –
fmlopes
当前模式如何,'活动'有很多'书签“? –