ruby on rails - How can I lock a model's associated collection? -
i have
class foo has_many :widgets end
there's place want pull widgets locked select. so, want equivalent of:
@widgets_to_work_with = widget.find_all_by_foo_id(@foo.id, :lock => true)
with nicer code, like:
@widgets_to_work_with = @foo.widgets(:lock => true)
what's best way this?
you redefine method widgets in foo activerecord or , safer ,add method a.e.
# in foo.rb #... def self.locked_widgets widget.find_all_by_foo_id(self.id, :lock => true) end
hope usefull
Comments
Post a Comment