I have
class Foo
has_many :widgets
end
There's a place where I want to pull up all the widgets with a locked select. So, I want to do the equivalent of:
@widgets_to_work_with = Widget.find_all_by_foo_id(@foo.id, :lock =>开发者_JAVA技巧 true)
With nicer code, something like:
@widgets_to_work_with = @foo.widgets(:lock => true)
What's the best way to do this?
you could redefine the method widgets in Foo ActiveRecord or , safer ,add another method a.e.
# in Foo.rb
#...
def self.locked_widgets
Widget.find_all_by_foo_id(self.id, :lock => true)
end
hope could be usefull
精彩评论