Pull recent Metastore::PG fixes into Metastore::PgGraph.
authorMahlon E. Smith <mahlon@martini.nu>
Mon, 14 Dec 2015 15:42:13 -0800
changeset 3 5b4ee98d698c
parent 2 58b5d17f0d53
child 6 4450ba4a0937
Pull recent Metastore::PG fixes into Metastore::PgGraph.
lib/thingfish/metastore/pggraph.rb
lib/thingfish/metastore/pggraph/node.rb
--- a/lib/thingfish/metastore/pggraph.rb	Thu Nov 05 10:40:01 2015 -0800
+++ b/lib/thingfish/metastore/pggraph.rb	Mon Dec 14 15:42:13 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 10:40:01 2015 -0800
+++ b/lib/thingfish/metastore/pggraph/node.rb	Mon Dec 14 15:42:13 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
 		#########