Ben W. wrote:
Well, I’m looking for a single query to be sent to the database. But
apart from that, as far as I see your solution adds the king and ace
cards to the decks, actually modifying the database, which I don’t want.
I simply want to query for all decks that already contain at least 1
king and at least 1 ace, without using excessive amounts of SQL.
Oh, does it mean deck is a table ? if so, I think the following
association will help you further:
class Card < ActiveRecord::Base
has_many :deck, :through => :manifests
class CoolCards < ActiveRecord::Base
class Deck < ActiveRecord::Base
has_many :card, :through => :coolcard
now you check the match between the:
whether (Deck.coolcard_id == Card.coolcard_id) and then
whether (Deck.rank == ‘Ace’ or Deck.rank == ‘King’)