myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3617] branches/packs/app/models: fixed issue wit


From: noreply
Subject: [myexperiment-hackers] [3617] branches/packs/app/models: fixed issue with resource associations accessing the wrong research object
Date: Tue, 6 Aug 2013 10:03:23 +0000 (UTC)

Revision
3617
Author
dgc
Date
2013-08-06 10:03:22 +0000 (Tue, 06 Aug 2013)

Log Message

fixed issue with resource associations accessing the wrong research object

Modified Paths

Diff

Modified: branches/packs/app/models/research_object.rb (3616 => 3617)


--- branches/packs/app/models/research_object.rb	2013-07-31 13:24:34 UTC (rev 3616)
+++ branches/packs/app/models/research_object.rb	2013-08-06 10:03:22 UTC (rev 3617)
@@ -478,9 +478,9 @@
     object = root_folder
 
     while (bit = bits.shift)
-      folder_entry = object.proxies.find(:first, :conditions => { :entry_name => bit })
-      return nil if folder_entry.nil?
-      object = folder_entry.proxy_for
+      folder_entries = object.proxies.select { |p| p.entry_name == bit }
+      return nil if folder_entries.empty?
+      object = folder_entries.first.proxy_for
     end
 
     object

Modified: branches/packs/app/models/resource.rb (3616 => 3617)


--- branches/packs/app/models/resource.rb	2013-07-31 13:24:34 UTC (rev 3616)
+++ branches/packs/app/models/resource.rb	2013-08-06 10:03:22 UTC (rev 3617)
@@ -15,23 +15,57 @@
 
   belongs_to :content_blob, :dependent => :destroy
 
-  belongs_to :proxy_for,          :primary_key => :path, :foreign_key => :proxy_for_path,     :class_name => 'Resource'
-  has_one    :proxy,              :primary_key => :path, :foreign_key => :proxy_for_path,     :class_name => 'Resource', :conditions => 'is_proxy = 1', :dependent => :destroy
+  def proxy_for
+    research_object.resources.find(:first,
+        :conditions => { :path => proxy_for_path } )
+  end
 
-  has_one    :folder_entry,       :primary_key => :path, :foreign_key => :proxy_for_path,     :class_name => 'Resource', :conditions => 'is_folder_entry = 1', :dependent => :destroy
+  def proxy
+    research_object.resources.find(:first,
+        :conditions => { :proxy_for_path => path, :is_folder_entry => false } )
+  end
 
-  belongs_to :proxy_in,           :primary_key => :path, :foreign_key => :proxy_in_path,      :class_name => 'Resource'
-  has_many   :proxies,            :primary_key => :path, :foreign_key => :proxy_in_path,      :class_name => 'Resource'
+  def folder_entry
+    research_object.resources.find(:first,
+        :conditions => { :proxy_for_path => path, :is_folder_entry => true } )
+    # FIXME: dependent => destroy
+  end
 
-  belongs_to :aggregated_by,      :primary_key => :path, :foreign_key => :aggregated_by_path, :class_name => 'Resource'
-  has_many   :aggregates,         :primary_key => :path, :foreign_key => :aggregated_by_path, :class_name => 'Resource'
+  def proxy_in
+    research_object.resources.find(:first,
+        :conditions => { :path => proxy_in_path } )
+  end
 
-  belongs_to :ao_body,            :primary_key => :path, :foreign_key => :ao_body_path,       :class_name => 'Resource'
-  has_one    :ao_stub,            :primary_key => :path, :foreign_key => :ao_body_path,       :class_name => 'Resource'
+  def proxies
+    research_object.resources.find(:all,
+        :conditions => { :proxy_in_path => path } )
+  end
 
-  belongs_to :resource_map,       :primary_key => :path, :foreign_key => :resource_map_path,  :class_name => 'Resource'
-  has_one    :is_resource_map_to, :primary_key => :path, :foreign_key => :resource_map_path,  :class_name => 'Resource'
+  def aggregated_by
+    research_object.resources.find(:first,
+        :conditions => { :path => aggregated_by_path } )
+  end
 
+  def aggregates
+    research_object.resources.find(:all,
+        :conditions => { :aggregated_by_path => path } )
+  end
+
+  def ao_body
+    research_object.resources.find(:first,
+        :conditions => { :path => ao_body_path } )
+  end
+
+  def resource_map
+    research_object.resources.find(:first,
+        :conditions => { :path => resource_map_path } )
+  end
+
+  def is_resource_map_to
+    research_object.resources.find(:first,
+        :conditions => { :resource_map_path => path } )
+  end
+
   has_many :annotation_resources, :foreign_key => 'annotation_id', :dependent => :destroy
 
   validates_uniqueness_of :path, :scope => :research_object_id
@@ -147,9 +181,10 @@
 
   def update_graph!
 
-    new_description = create_rdf_xml { |graph| graph << description }
+    unless is_resource
 
-    unless is_resource
+      new_description = create_rdf_xml { |graph| graph << description }
+
       content_blob.destroy if content_blob
       update_attribute(:content_blob, ContentBlob.new(:data ="" new_description))
     end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]