ember.js - Ember Relationships without Ember Data -
I have an amber app where some models use amber data and do nothing. My question is the best way to build relationships between these models and to structure the model relations.
Model
Currently I have the following models:
- Food
- < Em>
- Food
- uses amber data
- There are many excerpts << Li>
- fraction
- Uses Amber Data
- Is A Food
- Foods
In my app, I need to have a unique record in which there is a
weight field with each part from any related
food Should remove somewhere values should be part of a meal.
Question
- Parts should have a model in it itself, we should store it in the form of a type of array-type structure in the form of a field
On food (example:
parts )? Consider that one part is not reusable and is only able to be associated with a single meal.
- If there is "yes" for # 1, how can my
food model DF look?
- As the
food does not use AMR data, is the best technique for defining the relationship between a fraction and food?
- Make a part of the food
- Li> Associate the part with food
- See all the components associated with food
Your help is highly appreciated.
Q1 : It should be an ideal in parts Should we be stored on a food field as a field in some type of array-like structure (example: part)?
I'm not sure that you are asking if there should be
fraction model or
part model. But whatever I think is that the solution is to create the
part as a code and the
food model for the
part You have the functionality to make a portion together, in my understanding part should be made without food (although it can link to food later).
Q2 : If "Yes" for # 1, then what could be my food look like a model definition?
The definition of the model is as follows:
App.Portion = DS.Model.extend ({weight: DS.attr (), food: DS.belongsTo ( 'Food', {async: true}}}); App.Meal = DS.Model.extend ({Episode: DS.hasMany ('part', {async: true})});
Q3 : What is the best way of amber data to define the relationship between food and food?
It is still better to use amber data to define the
food model, just define your custom adapter and serializer, the amber data manages the rest and the documents Is a good place to start. Below is a simple example.
// Just use it for "food adapter" and "food" for Aber data. App.FoodAdapter = DS.Adapter.extend ({find: function (store, type, id) {// Return value is passed for "serializer.extract", then "store.push" comes back ._exec ({url: '/ external / food', type: 'GET'}); createRecord: function () {}, updateRecord: function () {}, deleteRecord: function () {}, findAll: function } {}, FindQuery: function () {}, _ajax: function (option) {// Change the promise of jQuery to return standard promise Em.RSVP.cast ($. Ajax (options)}}}}); App.FoodSerializer = DS.Serializer.extend ({// Assume that json is: // {// "food_data": {// "name": "XXX", // "price": 100 //} Remove: function (store, type, payload, id, request type) {return payload.food_data;}, serialize: function () {}});
- If there is "yes" for # 1, how can my
- Parts should have a model in it itself, we should store it in the form of a type of array-type structure in the form of a field
- < Em>
Comments
Post a Comment