ember.js - How do I set up polymorphic relationships using ember-data -
so lets recipe has several ingredients of differing amounts.
recipe model
var recipe = ds.model.extend({ name: ds.attr('string'), ingredients: ds.hasmany('ingredient') });
ingredient model
var ingredient = ds.model.extend({ name: ds.attr('string'), recipes: ds.hasmany('recipe'), // amount? });
so amount of each ingredient depend on recipe. on own ingredient not have amount.
how go modeling data? right using fixtureadapter
until finish building interface.
using ember 1.5.1
, ember-data 1.0.0-beta.7+canary.b45e23ba
.
to answer first question:
define model so
app.comment = ds.model.extend({ message: ds.belongsto('message', { polymorphic: true }) });
and property needs additional property propertytype, defining relationship type
{ "message": 12, "messagetype": "post" }
https://github.com/emberjs/data/blob/master/transition.md#polymorphic-relationships
now second question, not sure if polymorphism necessary. might include joining record
var recipeingredient = ds.model.extend({ amount: ds.attr(), ingredient: ds.belongsto('ingredient') }); var recipe = ds.model.extend({ name: ds.attr('string'), ingredients: ds.hasmany('recipeingredient') });
Comments
Post a Comment