Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing Ember.js models inside sub-folders?

I have multiple models representing user data (profile, settings etc). These at the moment are stored in the models folder like so;

models
  -> user.js
  -> profile.js
  -> settings.js

What I would like to so is have a folder structure like so;

models
  -> user.js
  -> user (folder)
    -> profile.js
    -> settings.js

The user model (user.js) references the profile model (profile.js) like so;

import DS from "ember-data"; 
export default DS.Model.extend({
   NSP: DS.attr('string'),
   Status: DS.attr('string'),
   Profile: DS.belongsTo('profile', {embedded: 'always'})
});

I have tried to replace the DS.belongsTo('profile', {embedded: 'always'}) with the following:

  • DS.belongsTo('user.profile', {embedded: 'always'})
  • DS.belongsTo('user/profile', {embedded: 'always'})
  • DS.belongsTo('user-profile', {embedded: 'always'})

but this does not work.

Am I missing something here?

like image 669
JonathanBristow Avatar asked Nov 16 '14 09:11

JonathanBristow


1 Answers

Are you sure using "user/profile" doesn't work? I replicated your structure on my system and am getting "user" and "user/profile" models.

Do you have Ember Inspector installed on Firefox or Chrome? You can see the available models easily by going to the "Data" pane:enter image description here

like image 53
Ruaidhrí Primrose Avatar answered Nov 16 '22 06:11

Ruaidhrí Primrose