-1
我試圖更新一個ActiveRecord與軌道 - 更新的ActiveRecord列錯誤
@post.update_column('post_likes_count', @post.post_likes_count - 1)
我敢肯定的是,@post存在,但我得到的錯誤信息:
ActiveRecord::ActiveRecordError (post_likes_count is marked as readonly):
帖子的模型定義爲
class Post < ActiveRecord::Base
belongs_to :user
has_many :post_comments, :dependent => :destroy
has_many :post_likes, :dependent => :destroy
has_many :post_hashtags, :dependent => :destroy
validates_presence_of :user_id
end
我在做什麼錯了?
我想要做的是減少post_likes_count
列。