Last active
April 4, 2016 22:45
-
-
Save ludalex/982ba10b24a1cc557277fc041cb9a39a to your computer and use it in GitHub Desktop.
filter hasMany relationship
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 Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
filteredModel: Ember.computed('model.[]', 'searchQuery', function() { | |
let searchQuery = this.get('searchQuery'); | |
if(searchQuery) { | |
var promises = this.get('model').map( (entity) => { | |
return Ember.RSVP.hash({ | |
entity: entity, | |
assetIps: entity.get('assetIps').then((assetIps) => { | |
return assetIps.filter((assetIp) => { | |
return true; | |
}) | |
}) | |
}); | |
}) | |
Ember.RSVP.all(promises).then( (filteredProjects) => { | |
this.set('filteredProjects2', filteredProjects); | |
return filteredProjects; | |
}); | |
} else { | |
return this.get('model'); | |
} | |
}) | |
}); |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
ipNumber: DS.attr('string'), | |
archived: DS.attr('boolean') | |
}); |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
assetIps: DS.hasMany('asset-ip'), | |
name: DS.attr('string') | |
}); |
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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
this.store.push({ | |
data: [{ | |
id: 1, | |
type: 'entity', | |
attributes: { | |
name: 'entity 1', | |
}, | |
relationships: {} | |
}] | |
}); | |
let entity = this.store.peekRecord('entity', 1); | |
let ipAsset1 = this.store.createRecord('assetIp', { | |
ipNumber: "127.0.0.1", | |
archived: true | |
}); | |
let ipAsset2 = this.store.createRecord('assetIp', { | |
ipNumber: "127.0.0.2", | |
archived: false | |
}); | |
entity.get('assetIps').pushObjects([ipAsset1, ipAsset2]); | |
return this.store.peekAll('entity'); | |
}, | |
}); |
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.7.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.3.2", | |
"ember-data": "2.3.3", | |
"ember-template-compiler": "2.3.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment