Have you tried something like:
@users=User.find(:all,
team && {:conditions =>
["status = ''active'' and role =
''admin'' and team_id=?", team]
}
)
In other words, only add the condition if there is a team? (This idiom
assumes that there is no "team false"; that is, that team is either a
valid team id or it is nil.
--MarkusQ
On Sun, 2005-08-28 at 01:53, Dewey Howell wrote:> I would like to return users where team_id = team but if only if team
> exists. If it is null then I would like to return all team_id''s.
Is
> there an easy way to construct this select statement?
>
> Thanks,
> Dewey
> ----------------------
>
> team = params[:selected_team]
> @users=User.find(:all,
> :conditions => ["status = ''active'' and role =
''admin''
> and team_id=?", team])
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails