@@ -54,42 +54,51 @@ class DSHttpAdapter {
54
54
options = options || { }
55
55
options . params = options . params || { }
56
56
57
- let item
58
- let parentKey = resourceConfig . parentKey
59
57
let endpoint = options . hasOwnProperty ( 'endpoint' ) ? options . endpoint : resourceConfig . endpoint
60
- let parentField = resourceConfig . parentField
61
- let parentDef = resourceConfig . getResource ( resourceConfig . parent )
62
- let parentId = options . params [ parentKey ]
63
-
64
- if ( parentId === false || ! parentKey || ! parentDef ) {
65
- if ( parentId === false ) {
66
- delete options . params [ parentKey ]
58
+ let parents = resourceConfig . parents || ( resourceConfig . parent ? {
59
+ [ resourceConfig . parent ] : {
60
+ key : resourceConfig . parentKey ,
61
+ field : resourceConfig . parentField
67
62
}
68
- return endpoint
69
- } else {
70
- delete options . params [ parentKey ]
63
+ } : { } )
64
+
65
+ DSUtils . forOwn ( parents , function ( parent , parentName ) {
66
+ let item
67
+ let parentKey = parent . key
68
+ let parentField = parent . field
69
+ let parentDef = resourceConfig . getResource ( parentName )
70
+ let parentId = options . params [ parentKey ]
71
+
72
+ if ( parentId === false || ! parentKey || ! parentDef ) {
73
+ if ( parentId === false ) {
74
+ delete options . params [ parentKey ]
75
+ }
76
+ } else {
77
+ delete options . params [ parentKey ]
71
78
72
- if ( DSUtils . _sn ( id ) ) {
73
- item = resourceConfig . get ( id )
74
- } else if ( DSUtils . _o ( id ) ) {
75
- item = id
76
- }
79
+ if ( DSUtils . _sn ( id ) ) {
80
+ item = resourceConfig . get ( id )
81
+ } else if ( DSUtils . _o ( id ) ) {
82
+ item = id
83
+ }
84
+ console . log ( 'item' , item )
77
85
78
- if ( item ) {
79
- parentId = parentId || item [ parentKey ] || ( item [ parentField ] ? item [ parentField ] [ parentDef . idAttribute ] : null )
80
- }
86
+ if ( item ) {
87
+ parentId = parentId || item [ parentKey ] || ( item [ parentField ] ? item [ parentField ] [ parentDef . idAttribute ] : null )
88
+ }
81
89
82
- if ( parentId ) {
83
- delete options . endpoint
84
- let _options = { }
85
- DSUtils . forOwn ( options , ( value , key ) => {
86
- _options [ key ] = value
87
- } )
88
- return DSUtils . makePath ( this . getEndpoint ( parentDef , parentId , DSUtils . _ ( parentDef , _options ) ) , parentId , endpoint )
89
- } else {
90
- return endpoint
90
+ if ( parentId ) {
91
+ delete options . endpoint
92
+ let _options = { }
93
+ DSUtils . forOwn ( options , ( value , key ) => {
94
+ _options [ key ] = value
95
+ } )
96
+ endpoint = DSUtils . makePath ( this . getEndpoint ( parentDef , parentId , DSUtils . _ ( parentDef , _options ) ) , parentId , endpoint )
97
+ }
91
98
}
92
- }
99
+ } , this )
100
+
101
+ return endpoint
93
102
}
94
103
95
104
getPath ( method , resourceConfig , id , options ) {
0 commit comments