@@ -6,7 +6,7 @@ var x = null,
66function join ( table , column , index ) {
77 if ( column . oneToMany ) {
88 var ref = column . oneToMany ,
9- alias = { alias : ref . table + index } ;
9+ alias = ref . table + index ;
1010
1111 var joins = column . fk
1212 ? [ z . join ( table , column . fk , ref , ref . pk , alias ) ]
@@ -15,15 +15,15 @@ function join (table, column, index) {
1515 else if ( column . manyToMany ) {
1616 var ref = column . manyToMany . ref ,
1717 link = column . manyToMany . link ,
18- alias = { alias : ref . table + index } ;
18+ alias = ref . table + index ;
1919
2020 var joins = [
2121 z . join ( table , table . pk , link , link . parentPk ) ,
2222 z . join ( link , link . childPk , ref , ref . pk , alias )
2323 ] ;
2424 }
2525
26- var concat = z . concat ( ref . columns , alias . alias , undefined , ' ' ) ,
26+ var concat = z . concat ( ref . columns , alias , undefined , ' ' ) ,
2727 group = z . group ( concat ) ;
2828
2929 return {
@@ -52,12 +52,14 @@ function select (args) {
5252 names . push ( x . name ( columns [ i ] . name , table . name , z . schema ( table ) ) ) ;
5353 }
5454 }
55- names . unshift ( x . as ( z . concat ( table . pk , table . name , z . schema ( table ) , ',' ) , x . name ( '__pk' ) ) ) ;
55+ if ( ! table . view )
56+ names . unshift ( x . as ( z . concat ( table . pk , table . name , z . schema ( table ) , ',' ) , x . name ( '__pk' ) ) ) ;
5657
5758 var where = statement ( table , columns , args . filter , joins ) ;
5859
5960 // always group by pk inside the listview!
6061 var group = ( function groupby ( ) {
62+ if ( table . view ) return ;
6163 var pk = ( table . pk instanceof Array ) ? table . pk : [ table . pk ] ;
6264 return x . groupby ( x . names ( pk , table . name ) ) ;
6365 } ( ) ) ;
@@ -76,8 +78,13 @@ function select (args) {
7678 }
7779 }
7880 else if ( ! Object . keys ( view . listview . order ) . length ) {
79- var pk = table . pk instanceof Array ? table . pk [ 0 ] : table . pk ;
80- order = x . name ( pk , table . name , z . schema ( table ) ) + ' asc' ;
81+ if ( table . view ) {
82+ order = names [ 0 ] + ' asc' ;
83+ }
84+ else {
85+ var pk = table . pk instanceof Array ? table . pk [ 0 ] : table . pk ;
86+ order = x . name ( pk , table . name , z . schema ( table ) ) + ' asc' ;
87+ }
8188 }
8289 else {
8390 order = ( function ( table , list ) {
@@ -184,7 +191,9 @@ function pagination (args) {
184191 var concat = z . concat ( table . pk , table . name , z . schema ( table ) , ',' ) ;
185192
186193 var str = [
187- x . select ( x . as ( x . func ( 'count' , [ 'distinct' , concat ] , ' ' ) , x . name ( 'count' ) ) ) ,
194+ x . select (
195+ table . view ? '*'
196+ : x . as ( x . func ( 'count' , [ 'distinct' , concat ] , ' ' ) , x . name ( 'count' ) ) ) ,
188197 x . from ( s . table ) ,
189198 s . join ,
190199 s . where ,
0 commit comments