Quote (carteblanche @ Jun 15 2014 03:46pm)
if colors.color_name is a single color, please show me sample data in your database to represent this.
assuming this is the colors table:
color_id = 1, color_name = black
color_id = 2, color_name = blue
color_id = 3, color_name = red
color_id = 4, color_name = green
i'm assuming this is how you set up your card:color correlations:
card_colors table:
card_id = 1, color_id = 4 -- this card is available in green
card_id=1, color_id = 2 -- this card is also available in blue
now how are you representing that the card is available in green, blue, and blue|green?
/edit: or is each card_id only associated with a single colour tuple?
Code
> Color.all
Color Load (2.4ms) SELECT "colors".* FROM "colors"
=> #<ActiveRecord::Relation [#<Color id: 1, color_name: "Blue", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 2, color_name: "Black", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 3, color_name: "Colorless", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 4, color_name: "Green", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 5, color_name: "Red", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 6, color_name: "White", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">]>
for a green black card:
Code
> card = Card.find(6805)
Card Load (0.7ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = $1 LIMIT 1 [["id", 6805]]
=> #<Card id: 6805, name: "Deathrite Shaman", mana_cost: "{B/G}", loyalty: nil, img_link: nil, converted_mana_cost: 1.0, oracle: "{T}: Exile target land card from a graveyard. Add o...", rarity: "Rare", power: 1, toughness: 2, mtg_set_id: 31, created_at: "2014-06-13 22:35:39", updated_at: "2014-06-13 22:35:39">
Code
> card.colors
Color Load (2.4ms) SELECT "colors".* FROM "colors" INNER JOIN "cards_colors" ON "colors"."id" = "cards_colors"."color_id" WHERE "cards_colors"."card_id" = $1 [["card_id", 6805]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Color id: 2, color_name: "Black", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">,
#<Color id: 4, color_name: "Green", created_at: "2014-06-13 22:33:35", updated_at: "2014-06-13 22:33:35">]>