From 9ea613cf4eb01d23573c5405a879f8528c15e8a1 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 16 Jan 2012 08:14:05 +0800 Subject: [PATCH] Embed attribute_fields and sub_roles --- app/models/user/attribute.rb | 2 +- app/models/user/attribute_field.rb | 2 +- app/models/user/role.rb | 2 +- app/models/user/sub_role.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user/attribute.rb b/app/models/user/attribute.rb index af8a1106..84650421 100644 --- a/app/models/user/attribute.rb +++ b/app/models/user/attribute.rb @@ -7,7 +7,7 @@ class Attribute field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - has_many :attribute_fields, :autosave => true, :dependent => :destroy + embeds_many :attribute_fields, :cascade_callbacks => true has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :attribute_fields, :allow_destroy => true diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index 42bbf910..2d909b3e 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -10,7 +10,7 @@ class AttributeField field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - belongs_to :attribute + embedded_in :attribute has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :attribute_values diff --git a/app/models/user/role.rb b/app/models/user/role.rb index 86f7266f..788d281d 100644 --- a/app/models/user/role.rb +++ b/app/models/user/role.rb @@ -7,7 +7,7 @@ class Role field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - has_many :sub_roles, :autosave => true, :dependent => :destroy + embeds_many :sub_roles, :cascade_callbacks => true has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :users accepts_nested_attributes_for :i18n_variable, :allow_destroy => true diff --git a/app/models/user/sub_role.rb b/app/models/user/sub_role.rb index cdefb5f5..47f3e2de 100644 --- a/app/models/user/sub_role.rb +++ b/app/models/user/sub_role.rb @@ -1,6 +1,6 @@ class SubRole < Attribute - belongs_to :role + embedded_in :role has_and_belongs_to_many :users # Get an sub_role from key