Có cách nào để ghi đè lên một bộ setter hoặc getter cho một mô hình trong Mongoid không? Một cái gì đó như:Ghi đè lên các bộ định vị và hình dáng của mô hình Mongoid
class Project
include Mongoid::Document
field :name, :type => String
field :num_users, type: Integer, default: 0
key :name
has_and_belongs_to_many :users, class_name: "User", inverse_of: :projects
# This will not work
def name=(projectname)
@name = projectname.capitalize
end
end
phương pháp name
có thể được ghi đè mà không sử dụng các trường ảo?
liên quan: http://stackoverflow.com/questions/6699503/mongoid-custom-setters-getters-and-super – marcgg