【发布时间】:2013-07-30 12:19:03
【问题描述】:
我基本上想要以下函数,但反过来,我已经有 undestroy 函数适用于单个类。
但是,我试图扩展 ActiveRecord::Relation 无济于事。以下是我对ActiveRecord::Base的其他方法的操作方法
ActiveRecord::Base.extend Track::BaseTrack
但是使用ActiveRecord::Relation.extend Track::TrackRelation 似乎没有任何作用。模块TrackRelation(在Track内)是:
module TrackRelation
def undestroy_all(conditions = nil)
if conditions
where(conditions).undestroy_all
else
to_a.each {|object| object.undestroy }.tap { reset }
end
end
end
我是否为关系使用了正确的 ActiveRecord 类?
错误是:
undefined method "undestroy_all" for #<ActiveRecord::Relation []>
【问题讨论】:
标签: ruby-on-rails ruby activerecord