title: rails : what's wrong with this multiple join with conditions on the associations?
body: <p>Here are my models:</p>
  
  <pre><code>class Deck &lt; ActiveRecord::Base
    belongs_to :game
    has_many :deck_cards
  end
  
  class DeckCard &lt; ActiveRecord::Base
    belongs_to :card
    belongs_to :deck
  end
  
  class Card &lt; ActiveRecord::Base
  end
  </code></pre>
  
  <p>Here's my attempted find:</p>
  
  <pre><code>DeckCard.all :joins =&gt; [:card, :deck], :conditions =&gt; {{:decks =&gt; {:game_id =&gt; @game.id}}, {:cards =&gt; {:present =&gt; true}}}
  </code></pre>
  
  <p>I keep getting the error : undefined method for <code>all</code> for #Class:0x4b2a98>.  I'm assuming this is a misleading error from parsing my conditions.  I'm following the guide for Active Record Query. I wasn't sure about whether to use the singular or plural form of the associations. Look like with a belongs_to, you're supposed to use singular form in the :joins hash, but I wasn't sure in the :conditions hash, so I tried both and neither worked.</p>
  
  <p>In case it isn't clear, what I'm trying to do in SQL is:</p>
  
  <pre><code>SELECT * from DeckCards  
  INNER JOIN decks on decks.id = deck_cards.deck_id  
  INNER JOIN cards on card.id = deck_cards.card_id  
  WHERE decks.game_id = 4  
  AND cards.present = true
  </code></pre>
  
  <p>I'm able to get around it for now by using <code>DeckCard.find_by_sql</code>, but it would be nice to figure out why the joins and conditions on associations isn't working.</p>
  
  <p>I'm using InstantRails-2.0 on windows, which is using Rails 2.0.2</p>
  
  <p>Edited : some progress using <code>DeckCard.find(:all ...)</code> instead. I also edited the brackets based on another answer. My latest code is</p>
  
  <pre><code>DeckCard.find :all, :joins =&gt; [:card, :deck], :conditions =&gt; {:deck =&gt; {:game_id =&gt; @game.id}, :cards =&gt; {:present =&gt; true}}  
  </code></pre>
  
  <p>which is producing the following error:  </p>
  
  <pre><code>Unknown column 'deck_cards.decks' in 'where clause': SELECT `deck_cards`.* FROM `deck_cards`   INNER JOIN `cards` ON `cards`.id = `deck_cards`.card_id  INNER JOIN `decks` ON `decks`.id = `deck_cards`.deck_id  WHERE (`deck_cards`.`decks` = '--- \n- :game_id\n- 5\n' AND `deck_cards`.`cards` = '--- \n- :present\n- true\n')  
  </code></pre>
  
  <p>The joins appear correct but not the WHERE conditions. I've tried a few different things like <code>:deck</code> or <code>:decks</code> in the conditions clause but no luck. Could this be another difference between the current ActiveRecord Query Interface docs and how conditions are done in 2.0.2?</p>
  
  <p>Thanks!</p>