Thanks for all the help.<br><br>Pratik, I have had success with your solution. I had to use:<br><br>
Monitor.find :all, :joins => [:features, :features], :conditions =><br>
["<a href="http://features.name/" target="_blank">features.name</a> = ? AND <a href="http://features_items.name/" target="_blank">features_monitors.name</a> = ?", 'white', 'big']<br><br>Using your original line, mysql could not find <a href="http://features_items.name">features_items.name</a> of the second join.<br>
<br>It seems strange how Rails renames the second join to 'features_monitors'. Here's the MySQL output:<br><br>SELECT `monitors`.* FROM `monitors` INNER JOIN `monitor_features` ON monitor_features.piuid = monitors.piuid INNER JOIN `monitor_features` features_monitors ON features_monitors.piuid = monitors.piuid WHERE (monitor_features.feature_code = 'white' AND features_monitors.feature_code = 'big')<br>
<br>In my application, it will need to match multiple features. For 3 joins, the MySQL join fragment looks like:<br>INNER JOIN `monitor_features` features_monitors_2<br><br>I get it now! <br><br>It's to do with this in Monitor:<br>
has_many :features, :class_name => "MonitorFeatures"<br><br>Thanks for your inputs Ben, Mathew and Pratik.<br><br>Xin<br><br><br><br><br><br><br><div class="gmail_quote">2008/5/25 Pratik Naik <<a href="mailto:pratik@thinkwares.com">pratik@thinkwares.com</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Try :<br>
<br>
Monitor.find :all, :joins => [:features, :features], :conditions =><br>
["<a href="http://features.name" target="_blank">features.name</a> = ? AND <a href="http://features_items.name" target="_blank">features_items.name</a> = ?", 'white', 'big']<br>
<div><div></div><div class="Wj3C7c"><br>
On Sat, May 24, 2008 at 8:26 PM, Xin Zheng <<a href="mailto:xin@zenpow.com">xin@zenpow.com</a>> wrote:<br>
> Hi Guys,<br>
><br>
> For the life of me I can't figure this out. I think it requires a MySQL<br>
> solution than Rails. Anyway, here's my problem illustrated<br>
><br>
> Models:<br>
><br>
> Monitor (computer monitors)<br>
> has_many :features<br>
><br>
> Feature:<br>
> name = [big, small, black, white]<br>
><br>
> I want to find a Monitor that is BOTH white and big.<br>
><br>
> My first shot at this:<br>
> find(:all, :include => :features, :conditions => ["name IN ('white',<br>
> 'big')" )<br>
><br>
> But this query will find Monitors that's EITHER white or big.<br>
><br>
> Can anyone help at all?<br>
><br>
> Xin<br>
</div></div><div class="Ih2E3d">> _______________________________________________<br>
> Chat mailing list<br>
> <a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
> <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
><br>
><br>
<br>
<br>
<br>
</div><font color="#888888">--<br>
<a href="http://m.onkey.org" target="_blank">http://m.onkey.org</a><br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</div></div></blockquote></div><br>