if my category_id could be either nil or a int value, how can I specify a condition that handles both? conditions => ["parent_id = ?",params[:category_id]] conditions => ["parent_id is ?",params[:category_id]] I''m using acts_as_tree which meets the root levels have no parent_id (null in SQL) so if no category_id is passed as a parameter I want it to pull up the roots, if one is passed, I want it to pull the children of that node. -- Posted via http://www.ruby-forum.com/.
On Jul 3, 11:27 pm, Grayson Piercee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> if my category_id could be either nil or a int value, how can I specify > a condition that handles both? > > conditions => ["parent_id = ?",params[:category_id]] > conditions => ["parent_id is ?",params[:category_id]] >It you do :conditions => {:parent_id => params[:category_id]} it should handle the case where params[:category_id] is nil. Fred> I''m using acts_as_tree which meets the root levels have no parent_id > (null in SQL) > so if no category_id is passed as a parameter I want it to pull up the > roots, if one is passed, I want it to pull the children of that node. > -- > Posted viahttp://www.ruby-forum.com/.
Grayson Piercee wrote: [...]> I''m using acts_as_tree which meets the root levels have no parent_id > (null in SQL) > so if no category_id is passed as a parameter I want it to pull up the > roots, if one is passed, I want it to pull the children of that node.You should probably be using something like awesome_nested_set instead -- it allows for much more efficient DB operations. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.