From 8f36f5a2d8004dbf805eb8f197590e3d990ddf76 Mon Sep 17 00:00:00 2001 From: did Date: Sat, 21 May 2011 01:02:03 +0200 Subject: [PATCH] solve a bug on has_ony / has_many caused by the caching mechanism --- app/models/content_instance.rb | 8 ++++++++ app/views/admin/custom_fields/types/_has_many.html.haml | 2 ++ app/views/admin/custom_fields/types/_has_one.html.haml | 2 ++ 3 files changed, 12 insertions(+) diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb index 08b48964..70a55112 100644 --- a/app/models/content_instance.rb +++ b/app/models/content_instance.rb @@ -53,6 +53,14 @@ class ContentInstance Hash.new.replace(self.errors) end + def reload_parent! + self.class.reload_parent! + end + + def self.reload_parent! + self._parent = self._parent.reload + end + def to_liquid Locomotive::Liquid::Drops::Content.new(self) end diff --git a/app/views/admin/custom_fields/types/_has_many.html.haml b/app/views/admin/custom_fields/types/_has_many.html.haml index a6a40f7d..b167ebc5 100644 --- a/app/views/admin/custom_fields/types/_has_many.html.haml +++ b/app/views/admin/custom_fields/types/_has_many.html.haml @@ -1,3 +1,5 @@ +- field.target.constantize.reload_parent! # to make sure all the contents from the parent are loaded + = form.custom_input field._alias.to_sym, :label => field.label, :hint => field.hint, :css => 'has-many' do .has-many-selector diff --git a/app/views/admin/custom_fields/types/_has_one.html.haml b/app/views/admin/custom_fields/types/_has_one.html.haml index 67c3aaec..86995ef3 100644 --- a/app/views/admin/custom_fields/types/_has_one.html.haml +++ b/app/views/admin/custom_fields/types/_has_one.html.haml @@ -1,2 +1,4 @@ +- field.target.constantize.reload_parent! # to make sure all the contents from the parent are loaded + = form.input field._alias.to_sym, :label => field.label, :hint => field.hint, :input_html => { :class => 'has_one' }, :as => :select, :collection => options_for_has_one(field), :selected => form.object.send(field._alias.to_sym).try(:_id)