fix foreign key should be ObjectID
This commit is contained in:
parent
8f5c6d1a56
commit
11991320d2
|
@ -4,8 +4,19 @@ class Component < Item
|
||||||
|
|
||||||
key :engine_name, String
|
key :engine_name, String
|
||||||
key :layout_name, String, :required => true
|
key :layout_name, String, :required => true
|
||||||
key :layout_id, String, :required => true
|
key :layout_id, ObjectId, :required => true
|
||||||
|
|
||||||
belongs_to :layout
|
belongs_to :layout
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def setup_default_value
|
||||||
|
super
|
||||||
|
|
||||||
|
if self.layout_name
|
||||||
|
self.layout_id = Layout.find_by_name( self.layout_name ).id
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -7,7 +7,7 @@ class Item
|
||||||
key :name, String, :required => true, :index => true
|
key :name, String, :required => true, :index => true
|
||||||
|
|
||||||
key :parent_name, String, :index => true
|
key :parent_name, String, :index => true
|
||||||
key :parent_id, String, :index => true
|
key :parent_id, ObjectId, :index => true
|
||||||
|
|
||||||
key_i18n :title, String, :required => true
|
key_i18n :title, String, :required => true
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class Item
|
||||||
|
|
||||||
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
|
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
|
||||||
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
|
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
|
||||||
many :children, :class_name => "Item", :foreign_key => :parent_id
|
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy
|
||||||
|
|
||||||
before_validation :setup_default_value
|
before_validation :setup_default_value
|
||||||
|
|
||||||
|
@ -44,11 +44,6 @@ class Item
|
||||||
else
|
else
|
||||||
self.parent_id = Item.find_by_name( self.parent_name ).id
|
self.parent_id = Item.find_by_name( self.parent_name ).id
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.layout_name
|
|
||||||
self.layout_id = Layout.find_by_name( self.layout_name ).id
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -4,8 +4,19 @@ class Page < Item
|
||||||
|
|
||||||
key_i18n :content, String
|
key_i18n :content, String
|
||||||
key :layout_name, String, :required => true
|
key :layout_name, String, :required => true
|
||||||
key :layout_id, String, :required => true
|
key :layout_id, ObjectId, :required => true
|
||||||
|
|
||||||
belongs_to :layout
|
belongs_to :layout
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def setup_default_value
|
||||||
|
super
|
||||||
|
|
||||||
|
if self.layout_name
|
||||||
|
self.layout_id = Layout.find_by_name( self.layout_name ).id
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue