Reputation: 8020
Is it possible to save a new record using createRecord()
and specify a custom key to save that new record under?
At the moment when using createRecord()
it's the same as using push()
in the javascript framework.
Obviously the following:
var myObj = this.store.createRecord('myObj', {
attr1: "Test"
})
myObj.save();
creates a new record with a key similiar to -KBCqhu4mhvl6xNfSRD3
.
My problem is that there are some of my keys in different endpoints where I would like the keys to be the same as the user's id.
To clarify further, here is an example of what I would like my Firebase structure to end up as:
FB
|
|
users--
| |
| userID1--
| | |
| | userAttr1
| | |
| | userAttr2
| |
| userID2--...
|
drivers--
|
userID1--
|
driverAttr1
|
driverAttr2
Let me know if I can clarify further
Upvotes: 1
Views: 189
Reputation: 1
Include an id
parameter in your createRecord request. That's it.
var myObj = this.store.createRecord('project', {
id: 12345,
name: "Big Project"
})
myObj.save()
Results in the data structure:
{projects: {
12345: {
name: "Big Project"
}
}
(I had the same question and stumbled on the answer. It's not very well documented.)
Upvotes: 0