相关疑难解决方法(0)

导致此ActiveRecord :: ReadOnlyRecord错误的原因是什么?

这是在这个先前的问题之后得到回答的.我实际上发现我可以从该查询中删除一个连接,所以现在工作查询是

start_cards = DeckCard.find :all, :joins => [:card], :conditions => ["deck_cards.deck_id = ? and cards.start_card = ?", @game.deck.id, true]  
Run Code Online (Sandbox Code Playgroud)

这似乎有效.但是,当我尝试将这些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
Run Code Online (Sandbox Code Playgroud)

和相关的模特(画面是桌上的球员卡)

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 …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord join ruby-on-rails associations

203
推荐指数
5
解决办法
7万
查看次数

标签 统计

activerecord ×1

associations ×1

join ×1

ruby ×1

ruby-on-rails ×1