PlaylistController のメソッドに送信するフォームがあります。そのフォームの送信から、曲のレコードを作成してコミットします。何が起こっているかというと、すべての提出物が正常に機能するということです。新しいレコードが保存され、コミットされます。App.Song.find() を実行して、コンテンツが更新されたことを確認できます。
しかし、2回目の提出はうまくいきません。送信は実際には新しいレコードとしてコミットされ、モデルに移動すると、別の新しい値が保存されていることがわかります。ただし、find() で .get('lastObject') を使用しようとすると、最初の送信が行われます。3 番目の送信は 2 番目の送信を返し、以降も同様です。
これが私のコードです:
// create song in Song model first
new_song = App.Song.createRecord({
name: 'test name',
artist: 'test username',
soundcloud: '/tracks/'
});
new_song.get('store').commit();
//can't return the song ID when commiting, so need to manually find it
// find all songs, return last result
last_song = App.Song.find().get('lastObject');
console.log(last_song);
そして、ここに console.log(songs_array.get('last_song')); があります。これを出力します:
Object {id: "ember914", clientId: 30, type: function, data: Object, record: Class}
Object {id: "ember914", clientId: 30, type: function, data: Object, record: Class…}
Object {id: "ember1200", clientId: 31, type: function, data: Object, record: Class…}
Object {id: "ember1408", clientId: 32, type: function, data: Object, record: Class…}