Creating child records with Ember-Model
I've been wrestling with what should be a simple task, using Ember-Model +
Ember.js + Ember-Model-Firebase-Adapter to create child records of a
parent record.
Can anyone provide a quick example of creating a Post and creating related
Comment too boot? Currently on mobile so I can't provide the code I've
been toying with, but later I can. I've been receiving a can't call save
on undefined error when attempting
post. get('comments').save();
I've tried defining post by
var post = App.Post.find();
But this is incorrect. I'm overlooking something simple, any insight or
quick examples out there? Would really appreciate some help.
[EDIT]
Thanks for the help so far. Currently getting an error which I'm looking
into:
Uncaught TypeError: Object [object Object] has no method 'create'
Here's my current controller:
App.PostController = Ember.ObjectController.extend({
newMessage: null,
actions: {
saveComment: function() {
var post = App.Post.create();
var comment = post.get('comments').create({message:
this.get('newMessage')});
comments.save();
post.save();
this.set('newMessage', null);
}
}
});
Should I be setting it as an array controller?
Here are my models:
App.Post = Ember.Model.extend({
id: attr(),
name: attr(),
comments: Ember.hasMany("App.Comment", {key: 'comment_ids'})
});
App.Game.url = "/posts";
App.Comment = Ember.Model.extend({
id: attr(),
message: attr(),
post: Ember.belongsTo('App.Post', {key: 'post_id'})
});
App.Comment.url = "/comments";
No comments:
Post a Comment