[英]Composite field in rails model
我在Rails中有這個模型:
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
end
並且我想添加字段payment_total = total*percentage
而無需在數據庫中創建該字段。
有些人將Presenter用於此類代碼,但是您可以選擇
class PaymentsDcument < ActiveRecord::Base
attr_accessible :date, :domain, :id, :total, :paid, :paid_left, :percentage
def payment_total
total*percentage
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.