ember.js - Mock many-to-many relationship using Ember CLI Mirage -


apologies in advance: new both ember (2.2.0) , mirage, , tasked creating acceptance tests existing ember application. challenge in using mirage (0.1.13) , fixtures (not factories) mock existing one-to-many or many-to-many relationships in our data. couldn't find complete examples model non-trivial relationships.

consider following simple many-to-many relationship: user can have multiple roles.

the respective ember models are:

// models/user.js import ember "ember"; import ds 'ember-data';  export default ds.model.extend({   email: ds.attr('string'),   //unidirectional m-m   roles: ds.hasmany('user-role', {inverse: null}) });  // models/user-role.js import ds 'ember-data';  export default ds.model.extend({   description: ds.attr('string') }); 

note user-role hyphenated.

my attempt @ creating fixtures:

// mirage/fixtures/users.js export default [   {id: 1, email: 'user@email.com', roles: {userrole_ids: [1]}},   {id: 2, email: 'supervisor@email.com', roles: {userrole_ids: [1, 2]}} ];  // mirage/fixtures/userroles.js export default [   {id: 1, description: 'regular user'},   {id: 2, description: 'supervisor'} ];  //mirage/config.js export default function() {   //...   //single user data   this.get('/users/:id', function(db, request) {     let id = request.params.id;     return db.users.find(id);   });   //... } 

when place breakpoint in finders.js on

var payload = normalizeresponsehelper(serializer, store, typeclass, adapterpayload, id, 'findrecord'); 

and inspect value of adapterpayload see, e.g.,

email: "supervisor@email.com" id: 2 roles: array[2]   0: object:     userrole_id: 1   1: object:     userrole_id: 2 

instead of expected

email: "supervisor@email.com" id: 2 roles: array[2]   0: object     id: 1     description: "regular user"   1: object     id: 2     description: "supervisor" 

in other words, user role id foreign key not resolved mirage corresponding record. suspect has hyphenation in user-role not matching naming of userroles.js file.

the back-end functionality (that attempting mock) implemented using jax-rs jpa , spring framework, shown below:

// user.java //... @entity @table(name = "user") public class user extends basebizobj<user, simpleprimarykey<string>, userrepository> {     //...     @manytomany(fetch = fetchtype.eager)     @joincolumn(name = "roles")     @notnull     @jsonproperty     private set<userrole> roles;     //... }  // userrole.java //... @entity @table(name = "userrole") public class user extends basebizobj<user, simpleprimarykey<string>, userrolerepository> {     //...     @column(name = "description")     @notnull     @jsonproperty     private string description;     //... } 

any appreciated.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -