Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4836

Mirage and Polymorphic models

$
0
0

@dnazarex wrote:

Hello, Dear Emberistas! :hamster:,

I try to understand how to work in Mirage with polymorphic models, I would appreciate any help with this.

My models:

// app/models/order.js

import Model from 'ember-data/model';
import { belongsTo } from 'ember-data/relationships';

export default Model.extend({
  product: belongsTo('product', { polymorphic: true })
});
// app/models/product.js

import Model from 'ember-data/model';
import { hasMany } from 'ember-data/relationships';

export default Model.extend({
  orders: hasMany('order', { inverse: 'product' }),
});
// app/models/product/vehicle/car.js

import Product from '../../product'
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';

export default Product.extend({
  description: attr('string', { defaultValue: '' }),
  model: attr('string', { defaultValue: '' }),

  pictures: hasMany('image')
});
// app/models/product/appliances/refrigerator.js

import Product from '../../product'
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';

export default Product.extend({
  brand: attr('string', { defaultValue: '' }),
  description: attr('string', { defaultValue: '' }),

  pictures: hasMany('image')
});

Let me know any idea how to mock it in Mirage.

Denis

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4836

Trending Articles