Foo
has_many Bar
。それはbars
関係で利用できるように、私はfind_with_custom_stuff
を定義するにはどうすればよいActiveRecordリレーションにカスタムファインダメソッドを定義しますか?
foo_instance.bars.find_with_custom_stuff(baz)
:私のような何かをしたいですか? (だけでなくBar
クラスメソッド?)
更新
私はスコープよりも複雑な何かをしたいです。以下のようなもの:レール
class Bar
scope :custom_find, lambda {|baz| where(:whatever => baz) }
end
foo_instance.bars.custom_find(baz)
scope
2.スコープを返すべきで
def find_with_custom_stuff(thing)
if relation.find_by_pineapple(thing)
relation.find_by_pineapple(thing).monkey
else
:banana
end
end
スコープ。 – rubish
私が追加したいものは、スコープよりはるかに複雑です。 –
あなたは範囲で複雑なものをたくさんすることができます、あなたは精巧にできますか? – numbers1311407