Can I set up a many-to-many relationship on just one side in Ember.js? -


in ember tutorial, many-to-many relationship introduced as:

app.post = ds.model.extend({   tags: ds.hasmany('app.tag') });  app.tag = ds.model.extend({   posts: ds.hasmany('app.post') }); 

is possible put 1 of these ds.hasmany relationships. example (let me know if code incorrect in way):

app.post = ds.model.extend({   postid: ds.attr('number'),   content: ds.attr('string'),   tags: ds.hasmany('app.tag') });  app.tag = ds.model.extend({   tagid: ds.attr('number'),   name: ds.attr('string') }); 

so can have json in these fixture adapter setup:

app.tag.fixtures = [{     tagid: 1111,     name: 'ember.js', }, {     tagid: 2222,     name: 'javascript' }];  app.post.fixtures = [{     postid: 3000,     content: 'a js question'     tags: [2222] }, {     postid: 4000,     content: 'an ember.js question',     tags: [1111, 2222] }]; 

so many-to-many relationship established in parent, that's why didn't include posts: ds.hsamany('app.post') in app.tag model.

is i'm doing okay? if so, when should need ds.hasmany in both models? if not, please correct fixture json well.

if type of adapter makes difference, please explain how they're different (related question).


update: since intuitivepixel clarified me relationship must many-to-many, let me try again:

app.post = ds.model.extend({   postid: ds.attr('number'),   content: ds.attr('string'),   tags: ds.hasmany('app.tag') });  app.tag = ds.model.extend({   tagid: ds.attr('number'),   name: ds.attr('string'),   posts: ds.hasmany('app.post') }); 

can fixture adapter setup this, relationship defined in posts?

app.tag.fixtures = [{     tagid: 1111,     name: 'ember.js', }, {     tagid: 2222,     name: 'javascript' }];  app.post.fixtures = [{     postid: 3000,     content: 'a js question'     tags: [2222] }, {     postid: 4000,     content: 'an ember.js question',     tags: [1111, 2222] }]; 

or have this, relationship defined in both. if so, wouldn't information redundant? redundancy terrible though. :(

app.tag.fixtures = [{     tagid: 1111,     name: 'ember.js',     posts: [4000] }, {     tagid: 2222,     name: 'javascript',     posts: [3000, 4000] }];  app.post.fixtures = [{     postid: 3000,     content: 'a js question'     tags: [2222] }, {     postid: 4000,     content: 'an ember.js question',     tags: [1111, 2222] }]; 

is possible put 1 of these ds.hasmany relationships.

yes, one-to-many relationship.

so many-to-many relationship established in parent, that's why didn't include posts: ds.hasmany('app.post') in app.tag model.

what trying doesn't work, need one-to-many relationship , models should like:

app.post = ds.model.extend({   postid: ds.attr('number'),   content: ds.attr('string'),   tags: ds.hasmany('app.tag') });  app.tag = ds.model.extend({   tagid: ds.attr('number'),   name: ds.attr('string')   post: ds.belongsto('app.post') }); 

and correspondent fixtures then:

app.tag.fixtures = [{   tagid: 1111,   name: 'ember.js',   post: 4000 }, {   tagid: 2222,   name: 'javascript',   post: 4000 }];  app.post.fixtures = [{   postid: 4000,   content: 'an ember.js question',   tags: [1111, 2222] }]; 

is i'm doing okay? if so, when should need ds.hasmany in both models?

it's not ok, imho (and because of nature of tag) should possible assign tag many posts, , many tags assigned post. end using many-to-many relationship in ember tutorial mentioned, there reason guess.

so final answer question: can set many-to-many relationship on just-one side in ember-js - no!

update

i've put togheter small example how many-to-many relationship work, see here.

hope helps.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -