@@ -2,7 +2,6 @@ import Ember from 'ember';
22import DS from 'ember-data' ;
33import Waitable from '../mixins/waitable' ;
44import toPromise from '../utils/to-promise' ;
5-
65import forEach from 'lodash/collection/forEach' ;
76import filter from 'lodash/collection/filter' ;
87import map from 'lodash/collection/map' ;
@@ -64,6 +63,7 @@ export default DS.Adapter.extend(Waitable, {
6463 */
6564 init ( application ) {
6665 this . _super . apply ( this , arguments ) ;
66+ // wilddogConfig会在子类中被赋值
6767 let wilddogConfig = this . get ( 'wilddogConfig' ) ;
6868 if ( ! wilddogConfig ) {
6969 throw new Error ( '请在适配器`application`中设置属性`wilddogConfig`!' ) ;
@@ -72,9 +72,6 @@ export default DS.Adapter.extend(Waitable, {
7272 // 获取野狗连接
7373 wilddog . initializeApp ( wilddogConfig ) ;
7474 let ref = wilddog . sync ( ) . ref ( ) ;
75- // if (!wd) {
76- // throw new Error('连接`widdog`失败!');
77- // }
7875 if ( ! ref ) {
7976 throw new Error ( 'Please set the `wildember` property in the environment config.' ) ;
8077 }
@@ -581,10 +578,31 @@ export default DS.Adapter.extend(Waitable, {
581578 * @return {Boolean } Is the relationship embedded?
582579 */
583580 isRelationshipEmbedded ( store , modelName , relationship ) {
584- var serializer = store . serializerFor ( modelName ) ;
585- return serializer . hasDeserializeRecordsOption ( relationship . key ) ;
581+ // var serializer = store.serializerFor(modelName);
582+ // return serializer.hasDeserializeRecordsOption(relationship.key);
583+ return this . hasDeserializeRecordsOption ( relationship . key ) ;
584+ } ,
585+
586+ // checks config for attrs option to deserialize records
587+ // a defined option object for a resource is treated the same as
588+ // `deserialize: 'records'`
589+ // 注意:从ember-data2.8版本开始没有这个方法!
590+ hasDeserializeRecordsOption ( attr ) {
591+ var alwaysEmbed = this . hasEmbeddedAlwaysOption ( attr ) ;
592+ var option = this . attrsOption ( attr ) ;
593+ return alwaysEmbed || ( option && option . deserialize === 'records' ) ;
586594 } ,
587595
596+ // checks config for attrs option to embedded (always) - serialize and deserialize
597+ hasEmbeddedAlwaysOption ( attr ) {
598+ var option = this . attrsOption ( attr ) ;
599+ return option && option . embedded === 'always' ;
600+ } ,
601+
602+ attrsOption ( attr ) {
603+ var attrs = this . get ( 'attrs' ) ;
604+ return attrs && ( attrs [ camelize ( attr ) ] || attrs [ attr ] ) ;
605+ } ,
588606
589607 /**
590608 * Determine from if the record is embedded via implicit relationships.
0 commit comments