branch merge
authorMahlon E. Smith <mahlon@martini.nu>
Mon, 14 Dec 2015 15:43:08 -0800
changeset 6 4450ba4a0937
parent 3 5b4ee98d698c (diff)
parent 5 cee945391bf2 (current diff)
child 7 f0ef12e25a2f
branch merge
--- a/lib/thingfish/metastore/pggraph.rb	Thu Nov 05 18:44:43 2015 +0000
+++ b/lib/thingfish/metastore/pggraph.rb	Mon Dec 14 15:43:08 2015 -0800
@@ -24,7 +24,7 @@
 
 
 	# Package version
-	VERSION = '0.1.0'
+	VERSION = '0.1.1'
 
 	# Version control revision
 	REVISION = %q$Revision$
@@ -175,7 +175,8 @@
 	### specified +oid+.
 	def fetch_value( oid, key )
 		metadata = self.model[ oid ] or return nil
-		return metadata.send( key )
+		key = key.to_sym
+		return metadata[ key ] || metadata.user_metadata[ key ]
 	end
 
 
@@ -200,6 +201,8 @@
 		ds = self.apply_search_direction( ds, options )
 		ds = self.apply_search_limit( ds, options )
 
+		self.log.debug "Dataset for search is: %s" % [ ds.sql ]
+
 		return ds.map {|row| row[:id] }
 	end
 
@@ -276,7 +279,8 @@
 	def apply_search_order( ds, options )
 		if options[:order]
 			columns = Array( options[:order] )
-			ds = ds.order( columns.map(&:to_sym) )
+			self.log.debug "  ordering results by columns: %p" % [ columns ]
+			ds = ds.order_metadata( columns )
 		end
 
 		return ds
--- a/lib/thingfish/metastore/pggraph/node.rb	Thu Nov 05 18:44:43 2015 +0000
+++ b/lib/thingfish/metastore/pggraph/node.rb	Mon Dec 14 15:43:08 2015 -0800
@@ -69,6 +69,24 @@
 		end
 
 
+		### Dataset method: Order results by the specified +columns+.
+		###
+		def order_metadata( *columns )
+			columns.flatten!
+			ds = self
+			columns.each do |column|
+				if Thingfish::Metastore::PG::Metadata.metadata_columns.include?( column.to_sym )
+					ds = ds.order_append( column.to_sym )
+				else
+					ds = ds.order_append( self.user_metadata_expr(column) )
+				end
+			end
+
+			return ds
+		end
+
+
+
 		#########
 		protected
 		#########