これは、回答済みのこの前の質問に続きます。私は実際にそのクエリから結合を削除できることを発見したので、現在の作業クエリは
start_cards = DeckCard.find :all, :joins => [:card], :conditions => ["deck_cards.deck_id = ? and cards.start_card = ?", @game.deck.id, true]
これはうまくいくようです。しかし、これらの DeckCards を別の関連付けに移動しようとすると、ActiveRecord::ReadOnlyRecord エラーが発生します。
これがコードです
for player in @game.players
player.tableau = Tableau.new
start_card = start_cards.pop
start_card.draw_pile = false
player.tableau.deck_cards << start_card # the error occurs on this line
end
および関連するモデル (テーブルはテーブル上のプレイヤー カードです)
class Player < ActiveRecord::Base
belongs_to :game
belongs_to :user
has_one :hand
has_one :tableau
end
class Tableau < ActiveRecord::Base
belongs_to :player
has_many :deck_cards
end
class DeckCard < ActiveRecord::Base
belongs_to :card
belongs_to :deck
end
このコードの直後に同様のアクションを実行DeckCards
し、プレイヤーの手に追加しましたが、そのコードは正常に機能しています。belongs_to :tableau
DeckCardモデルで必要かと思ったのですが、プレイヤーの手札に加えるのには問題ありません。DeckCard テーブルに と 列がありますtableau_id
。hand_id
Rails api で ReadOnlyRecord を調べましたが、説明以上のことは何も言っていません。