views:

31

answers:

3

What am I doing wrong here??

  features = WidgetFeature.all(:conditions => {:widget_id=>params[:id], :children_features=>nil, :filterable => true" })

I want to find all those features where widget_id = params[:id] AND children_features IS NIL AND filterable IS TRUE

A: 
features = WidgetFeature.all(:conditions => {:widget_id=>params[:id], :children_features=>nil, :filterable => true })

This works. I solved it.

Silver Spoon
A: 

Try this one:

features = WidgetFeature.find(:all, :conditions => "[widget_id=? and children_features is NULL and filterable = true", params[:id] ]")

This will help you..

A: 

IN my perception the best way of doing this is

WidgetFeature.some_name_for_named_scope(params[:id])

IN WidgetFeature Model

named_scope :some_name_for_named_scope, lambda { |widget_id| { :conditions => ["widget_id = ? AND children_features = ? AND filterable = ?", widget_id, nil, true] } }

please let me know what you or anyone think ?

Mayank Jaimini