我有两个模型Board
,并且Feed
与 join :through model 存在多对多关系Subscription
。
最近我向 中添加了root_id
字段Subscription
,并且我想在这样做时设置此字段@board.feeds << @feed
所以就像@board.feeds << @feed, root_id: 10
根据rails docs,我可以覆盖这些方法,但不确定如何。
def feeds << (??? - how should I setup arguments here? )
super
#super creates new Subscription rekord, but how can I access it
#to set root_id field?
#For now let say I accessed it as subscription
if root_id
subscription.root_id = root_id
else
subscription.root_id = self.id
end
subscription.save
#return something regular collection << returns
end