- :test #'tables-equal))))
- (dolist (ob (listify order-by))
- (when (and ob (not (member ob (mapcar #'cdr fullsels)
- :test #'ref-equal)))
- (setq fullsels
- (append fullsels (mapcar #'(lambda (att) (cons nil att))
- (listify ob))))))
- (dolist (ob (listify order-by-descending))
+ :test #'tables-equal)))
+ (order-by-slots (mapcar #'(lambda (ob) (if (atom ob) ob (car ob)))
+ (listify order-by))))
+
+
+ (when (and order-by-slots (= 1 (length tables)))
+ ;; Add explicity table name if not specified and only one selected table
+ (let ((table-name (sql-output (car tables) database)))
+ (loop for i from 0 below (length order-by-slots)
+ do (when (typep (nth i order-by-slots) 'sql-ident-attribute)
+ (unless (slot-value (nth i order-by-slots) 'qualifier)
+ (setf (slot-value (nth i order-by-slots) 'qualifier) table-name))))))
+
+ (dolist (ob order-by-slots)