ruby on rails(アクティブレコード)では、 update_counter
メソッドを呼び出すだけでカウンタを更新できます。例えば、レールに次のように記述する必要があります。Ecto/Phoenixでアップデートカウンターを実装する最善の方法は何ですか?
# For the Post with id of 5, decrement the comment_count by 1, and
# increment the action_count by 1
Post.update_counters 5, :comment_count => -1, :action_count => 1
# Executes the following SQL:
# UPDATE posts
# SET comment_count = comment_count - 1,
# action_count = action_count + 1
# WHERE id = 5
私は複数の列のカウンタを更新する必要が考慮エリクシル/フェニックスでこれを行う簡単な方法はありますか?あなたはinc
オプション使用して、このようなもので行くことができます
ご質問の改善点について、お気軽にご連絡ください。ありがとう – punitcse
タグを選択する際には注意してください。 [tag:phoenix]はこの質問とは関係ありません。 – mudasobwa
必ず@mudasobwa。アドバイスをいただきありがとうございます。 – punitcse