-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
When a new portfolio is created, the initial deposit gets saved as a new transaction. This data shows correctly in the browser at first, but disappears as soon as a refresh occurs. The transaction is not being persisted to the database.
var record = store.createRecord('portfolio', {
name: newPortfolio.name,
cash: parseFloat(newPortfolio.cash),
owner: owner
}),
transaction = store.createRecord('transaction', {
type: 'deposit',
ticker: null,
shares: null,
price: null,
value: parseFloat(newPortfolio.cash)
});
// New deposit is pushed
record.get('transactions').pushObject(transaction);
// Portfolio is saved, but new transaction isn't
record.save();I believe the issue has to do with the asynchronous call of functions. record.save() happens before the new transaction is pushed. Calling the save method within a promise was suggested online, but doing so yields errors:
record.get('transactions').then(function(transactions) {
transactions.pushObject(transaction);
record.save();
});
// Uncaught TypeError: record.get(...).then is not a functionReactions are currently unavailable