/ / 最新 / 2009-09 / RSS / twitter / tumblr / 09014502501 / mail@ssig33.com

屋久島沈没


Rails の find について

Shit.find(1) だとオブジェクトがそのまま返ってくる。
Shit.find([1,2,3]) だとオブジェクトが三つ入った配列が返ってくる。

そして、
Shit.find([1]) だとオブジェクトが一つ入った配列が返ってくる。

これに気付くまでに 2 週間ぐらいかかったし、これに気付いて大分楽になった。

まあでも実際には、 find の条件に ID だけを指定するとかありえないし、 Condition Builder とかいうプラグインを使うと楽だった。

fuck = [1,2,3]
shit = Shit.find(:all,
	:conditions => Condition.block do |c|
		fuck.each do |f|
			c.or 'id',f
		end
	end)

:
とかそんなん。これで

select * from shits where (id = 1) or (id = 2) or (id = 3)

:
相当な感じ。

何が言いたいかと言うと、 Condition Builder が便利、というそれだけの話でした。

blog comments powered by Disqus

Referrer (Inside):

[ 固定リンク ]