What would be the ember/ember-data way of creating a record for a record that is not the current routes record?
The scenario I have is I have an items route that finds is a list of items, when I click on one I transition to the item route which shows me all the info for that one item. I also have a bids resource but the way the bids will be worked with is always from an item route. So placing a bid happens on an item route.
So how would I go about tackling this? I was going to setup an ajax request in an action connected to my place bid button in the item route but I’m worried this might not be the ember way?
So what if I’m not going to display bids I’m just going to use them to update the item? It’s more like a silent auction idea so there is no need to show who is bidding on an item, more just that an item received a new bid so it’s bid amount needs updated. Could I stop with the RSVP.hash and not worry about setting up the controller or is all that still necessary to display the items?
If you just want to update the Item you can sent an action and add the bid data on handling that action. You can skip the bit: Ember.inject.controller() and skip sending the bid to a component.
Trying to explain this let you write strange sentences
Okay here is what I’ve tried and am getting an error.
In my item route where I’m also trying to do the save function here is my model I’m attempting
model(params) {
var store = this.store;
return Ember.RSVP.hash({
content: store.findRecord('item',params.item_id),
bids: store.findAll('bid')
});
},
And in the console on the item route I see this
Error while processing route: item DS.default.Attr is not a function TypeError: DS.default.Attr is not a function
at http://localhost:4200/assets/bidr.js:2162:28
at mod.state (http://localhost:4200/assets/vendor.js:150:29)
at tryFinally (http://localhost:4200/assets/vendor.js:30:14)
at requireModule (http://localhost:4200/assets/vendor.js:148:5)
at Ember.DefaultResolver.extend._extractDefaultExport (http://localhost:4200/assets/vendor.js:69229:20)
at resolveOther (http://localhost:4200/assets/vendor.js:68961:32)
at superWrapper (http://localhost:4200/assets/vendor.js:32770:20)
at exports.default._emberRuntimeSystemObject.default.extend.resolve (http://localhost:4200/assets/vendor.js:15520:35)
at Object.resolve [as resolver] (http://localhost:4200/assets/vendor.js:15276:23)
at resolve (http://localhost:4200/assets/vendor.js:12768:29)
I looked up the error and found this stack overflow question
Do I need to make a serializer for the item to tell it what the primary key is?
Also it would be really nice to only pull up bids for that particular item rather than all the bids, since when this gets hooked up to a server it will be a lot of bids.