Я хочу установить parent_id в дочерних записях.Как получить родительский идентификатор при создании дочернего элемента ember js
Мои модели - это рецепт (id, название) и ингредиенты (id, about, recipe_id).
У меня есть форма, где я создаю рецепт со многими ингредиентами. Все работает хорошо, но я не знаю, как установить parent_id в дочерних записях после создания родительской записи.
Пример:
Мы создаем рецепт (ID = 1, название = 'Title01'). Таким образом, все наши ингредиенты будут иметь поле recipe_id с 1 (ID = 2, о = 'это вещество', recipe_id = 1)
recipe.js.coffee
App.Recipe = DS.Model.extend
title: DS.attr('string')
ingredients: DS.hasMany('App.Ingredient')
ingredient.js.coffee
App.Ingredient = DS.Model.extend
about: DS.attr('string')
recipe: DS.belongsTo('App.Recipe')
new.emblem (здесь я создать родительский рецепт и дети Ингредиенты)
h1 Create recipe
form
div
label{bindAttr for='title.elementId'} Title
Ember.TextField valueBinding='title' name='title' viewName='title'
div
label{bindAttr for='about.elementId'} About
Ember.TextArea valueBinding='about' name='about' viewName='about'
#ingredients
h3 Ingredients
each ingredient in content.ingredients itemViewClass='App.ItemView'
h3= this.view.rebasedIndex
.control-group
.controls
Ember.TextField valueBinding='ingredient.about'
a{ action removeIngredient ingredient target='controller' } href='#' Remove
div
a{ action addIngredient target='controller' } href='#' Add Ingredient
button.btn.btn-success{ action save this } Create
button.btn.btn-inverse{ action cancel this } Cancel
вы можете дать мне пример, как это сделать? на js или кофе это не имеет значения. – EJIqpEP9