-
-
Save alexspeller/dd8c8ae3de3ffcf11521ddfe4601b082 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) { | |
debugger | |
return DS.PromiseArray.create({ | |
promise: Ember.RSVP.filter(this.get('model').toArray(), entity => {; | |
return entity.get('assetIps').then( assetIps => { | |
let res2 = assetIps.find( (assetIp) => { | |
let res = assetIp.get('ipNumber').toLowerCase().indexOf( searchQuery.toLowerCase() ) !== -1; | |
console.log('Searching IP between children', res); | |
return res; | |
}); | |
console.log('r', res2); | |
return res2; | |
}); | |
}) | |
}); | |
} 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') | |
}); |
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" | |
}); | |
let ipAsset2 = this.store.createRecord('assetIp', { | |
ipNumber: "127.0.0.2" | |
}); | |
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