Dani Dani wrote:
> 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 :coolcards
> has_many :deck, :through => :manifests
> end
>
> class CoolCards < ActiveRecord::Base
> belongs_to :card
> belongs_to :deck
> end
>
> class Deck < ActiveRecord::Base
> has_many :coolcards
> has_many :card, :through => :coolcard
> end
>
> now you check the match between the:
> whether (Deck.coolcard_id == Card.coolcard_id) and then
> whether (Deck.rank == 'Ace' or Deck.rank == 'King')
Unfortunately I don't quite understand what you are getting at here. Yes
deck is a table. This is the full schema, if that helps:
----------------------------
class Deck < ActiveRecord::Base
has_many :cards
end
class Card < ActiveRecord::Base
belongs_to :deck # a card is in 1 deck
belongs_to :material # a card is made of 1 material
end
class Material < ActiveRecord::Base
has_many :cards
end
------------------------------
The problem is to find all decks that already contain at least 1 king
and at least 1 ace where both ace and king are made of cardboard,
without using excessive amounts of SQL.
I'm not new to rails so I'm pretty sure I've gotten to grips with
has_many and belongs_to. That said, I often make stupid mistakes, so
don't be afraid to give me ideas.
Thanks,
ben