Last active
September 2, 2020 08:50
-
-
Save urbany/26f68cde34e59c46c0c4b8c47d808c42 to your computer and use it in GitHub Desktop.
Bug when sorting hasMany
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
import { sort } from '@ember/object/computed'; | |
import { A } from '@ember/array'; | |
export default class ApplicationController extends Controller { | |
appName = 'test' | |
get services() { | |
return this.model.services; | |
} | |
get sortedServices() { | |
return this.model.services.sortBy('name'); | |
} | |
get sortedThroughBusinessServices() { | |
return this.model.business.services.sortBy('name'); | |
} | |
_sortParams = ['name'] | |
@sort('model.services', '_sortParams') sortedServicesComputed | |
@action addService() { | |
const business = this.model.business; | |
const name = Math.round(Math.random()) ? 'John' : 'Doe'; | |
const service = this.store.createRecord('service', { name, business }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model, { hasMany } from '@ember-data/model'; | |
/* | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
*/ | |
export default class extends Model { | |
@hasMany('service', { inverse: 'business' }) services | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model, { attr, belongsTo } from '@ember-data/model'; | |
/* | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
*/ | |
export default class extends Model { | |
@attr() name | |
@belongsTo('business', { inverse: 'services' }) business | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
export default class extends Route { | |
async model() { | |
const business = this.store.createRecord('business'); | |
const services = await business.services; | |
return { business, services: services }; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.1", | |
"ember-data": "3.21.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment