I have an Ember App where some Models use Ember Data and some don't. My question relates to creating relationships between these Models and also the best way to structure the Model relationships.
Models
Currently I have the following Models:
- Foods
- Meals
- uses Ember Data
- has many Portions
- Portions
- uses Ember Data
- hasOne Meal
- hasOne Food
In my app I need a Portion to be a unique record which has a weight
field. Each Portion should derive it's other values from a associated Food
. A Meal should contain many Portions.
Questions
- Should Portions be a Model in it's own right our should it be stored in some kind of array-like structure as a field on the
Meal
(eg:portions
)? Consider that a Portion is not reusable and is only able to be associated with a single Meal. - If "Yes" to #1 then what could my
Meal
Model def look like? - As
Food
does not use Ember Data what's the best technique for defining a relationship between a Portion and a Food?
Ultimately the User experience should allow someone to
- View a Food
- Create a Portion of that Food
- Associate the Portion with a Meal
- View all Portions associated with a Meal
Your help is much appreciated.
Food
model? It seems a little silly that you already have it included and want to connect relationships to it, but don't want to define it as an Ember-Data model. – GJK$.ajax
, then you can write an Ember-Data adapter to handle it for you. You can also make it so than an adapter only handles one type of model instead of all of them. Take a look at this question for an example. – GJK