[LRUG] association finder query problem

Pratik Naik pratik at thinkwares.com
Sat May 24 17:19:33 PDT 2008


Try :

Monitor.find :all, :joins => [:features, :features], :conditions =>
["features.name = ? AND features_items.name = ?", 'white', 'big']

On Sat, May 24, 2008 at 8:26 PM, Xin Zheng <xin at zenpow.com> wrote:
> Hi Guys,
>
> For the life of me I can't figure this out. I think it requires a MySQL
> solution than Rails. Anyway, here's my problem illustrated
>
> Models:
>
> Monitor (computer monitors)
> has_many :features
>
> Feature:
> name = [big, small, black, white]
>
> I want to find a Monitor that is BOTH white and big.
>
> My first shot at this:
> find(:all, :include => :features, :conditions => ["name IN ('white',
> 'big')" )
>
> But this query will find Monitors that's EITHER white or big.
>
> Can anyone help at all?
>
> Xin
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>



-- 
http://m.onkey.org



More information about the Chat mailing list