私は 2 つのコントローラーと 2 つのモデルを持っています。(私は 3 番目の を持っていますがgroups
、この状況ではそれは問題ではありません。) 私のモデルは次のように関連付けられています。
App.Favorite = DS.Model.extend({
lodge: DS.belongsTo('lodge'),
notes: DS.attr('string'),
groups: DS.hasMany('group', {async:true}),
photo: DS.attr('string'),
});
App.Lodge = DS.Model.extend({
name: DS.attr('string'),
address: DS.attr('string'),
website: DS.attr('string'),
phone: DS.attr('string'),
uniqueDescription: DS.attr('string'),
basicDescription: DS.attr('string'),
yearOpened: DS.attr('string'),
propertySize: DS.attr('string'),
propertyType: DS.attr('string'),
languages: DS.attr('string'),
owner: DS.attr('string'),
uniqueQualifier1: DS.attr('string'),
uniqueQualifier2: DS.attr('string'),
uniqueQualifier3: DS.attr('string'),
uniqueQualifier4: DS.attr('string'),
lowDayPrice: DS.attr('string'),
highDayPrice: DS.attr('string'),
favoriteBoolean: DS.attr('boolean')
});
テンプレート内から、lodge
その特定のロッジをお気に入りに「割り当て」ようとしています。コントローラーfavorite
からモデルに新しいレコードを追加するにはどうすればよいですか? lodge
私が知る限り、Ember のガイドと API にはこのユースケースはないようです。
サンプル ロッジ コントローラー:
App.LodgeController = Ember.ObjectController.extend({
actions: {
createFavorite: function() {
// Not sure what to do here
//
// Create new record
//
// Then transition to newly created record route
}
}
});
ルート:
App.Router.map(function() {
this.resource('groups', { path: '/groups' });
this.resource('group', {path: '/group/:group_id'});
this.resource('favorites', {path: '/favorites'});
this.resource('lodges', {path: '/'});
this.resource('favorite', {path:'/favorite/:favorite_id'})
});