के साथ उलझन में मैं एम्बर डेटा 0.13 से 1.0.0 बीटा से माइग्रेट कर रहा हूं। दस्तावेज़ https://github.com/emberjs/data/blob/master/TRANSITION.md के अनुसार, अब प्रति प्रकार एडेप्टर और प्रति प्रकार serializers हैं।एम्बर डेटा 1.0.0: प्रति-प्रकार एडाप्टर और सीरियलाइज़र
इसका मतलब है कि अब मैं प्राथमिक कुंजी और प्रमाणीकरण के लिए कुछ विशिष्ट ओवरराइड के साथ "myRestAdapter" को परिभाषित नहीं कर सकता। मुझे प्रत्येक मॉडल प्रकार के लिए अब इस कोड को लागू करने की आवश्यकता है जिसके परिणामस्वरूप xx बार एक ही कोड डुप्लिकेट कर रहा है।
एंबर डेटा 0.13 में कोड:
App.AuthenticatedRestAdapter = DS.RESTAdapter.extend({
serializer: DS.RESTSerializer.extend({
primaryKey: function() {
return '_id';
}
}),
ajax: function (url, type, hash) {
hash = hash || {};
hash.headers = hash.headers || {};
hash.headers['Authorization'] = App.Store.authToken;
return this._super(url, type, hash);
}
});
कोड एंबर में डेटा 1.0.0 (केवल _ id के बजाय _ id के लिए प्राथमिक कुंजी स्थापित करने के लिए:
App.AuthorSerializer = DS.RESTSerializer.extend({
normalize: function (type, property, hash) {
// property will be "post" for the post and "comments" for the
// comments (the name in the payload)
// normalize the `_id`
var json = { id: hash._id };
delete hash._id;
// normalize the underscored properties
for (var prop in hash) {
json[prop.camelize()] = hash[prop];
}
// delegate to any type-specific normalizations
return this._super(type, property, json);
}
});
मैं इसे सही है कि समझ में आ गया है मुझे इस मॉडल को हर मॉडल के लिए कॉपी करने की आवश्यकता है जिसके लिए _id को प्राथमिक कुंजी के रूप में आवश्यकता है? क्या पूरे एप्लिकेशन के लिए इसे एक बार निर्दिष्ट करने का कोई तरीका नहीं है?
अच्छा सुझाव। इसका पालन करेंगे! धन्यवाद। मार्क – cyclomarc
ऐसे मॉडल करें जिनके पास टाइपटाइप एडेप्टर/सीरियलाइज़र नहीं हैं, अभी भी डिफॉल्ट एडाप्टर/सीरिएलाइज़र पर फ़ॉलबैक परिभाषित हैं? – mehulkar
@MehulKar मुझे डिफ़ॉल्ट एडाप्टर पर फ़ॉलबैक करने की संभावना नहीं मिली है। – cyclomarc