This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/models/user_attribute_model.rb

36 lines
818 B
Ruby
Raw Normal View History

class UserAttributeModel
include Mongoid::Document
field :key
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
2011-02-01 02:46:26 +00:00
embeds_many :attribute_models
after_update :destroy_attrs
2011-02-01 02:46:26 +00:00
# Update or create the attribute_model records
def attribute_models=(*attrs)
2011-01-28 06:44:08 +00:00
attrs[0].each do |attributes|
if attributes[:id].blank?
2011-02-01 02:46:26 +00:00
attribute_models.build(attributes)
else
2011-02-01 02:46:26 +00:00
attribute_model = attribute_models.detect {|a| a.id.to_s == attributes[:id].to_s }
attribute_model.update_attributes(attributes)
end
end
end
protected
2011-02-01 02:46:26 +00:00
# Destroy the i18n_variable for each attribute_models if marked to destroy
def destroy_attrs
2011-02-01 02:46:26 +00:00
attribute_models.each do |a|
if a.should_destroy?
2011-01-28 06:44:08 +00:00
a.destroy_i18n_variable
end
end
end
end