lundi 23 mars 2015

How to properly use Ember DS.Store method filter and is it correct for this particular use case

I have two models.


The first one: billable_group



import DS from 'ember-data';

export default DS.Model.extend({
start: DS.attr('string'),
end: DS.attr('string'),
total: DS.attr('number'),
createdOn: DS.attr('date'),
updatedOn: DS.attr('date'),
approvalStatus: DS.attr('string'),
billable_group_type: DS.attr('string'),

//relationships
matter: DS.belongsTo('matter', {async: true}),
billables: DS.hasMany('billable'),
receipts: DS.hasMany('receipts'),
charges: DS.hasMany('charge'),
updatedBy: DS.belongsTo('employee', {async: true, inverse: 'updatedBys'}),
createdBy: DS.belongsTo('employee', {async: true, inverse: 'createdBys'}),
approvedBy: DS.belongsTo('employee', {async: true, inverse: 'approvedBys'})
});


The other model is: expense_report_has_matter


import DS from 'ember-data';



export default DS.Model.extend({
billableGroup: DS.belongsTo('billable_group'),
matter: DS.belongsTo('matter'),
isChecked: DS.attr('boolean', {defaultValue: false})
});


ultimately i need to grab the billable group records of type "time and expense" that are associated with a particular billable_group record of type "expense report" and get a distinct list of the 'matters_id' that these billable_group of type "time and expense" records are associated with. I have that much working. Is is just a simple array of id's.



['234','253','25']


Now, i need to loop through this array of id's and determine whether each id is already associated with a 'expense_report_has_matter' record that has the same id as its matters_id.


What is the best way in ember to answer the question: do any of the records of 'expense_report_has_matter' have '235' as their matter_id.


I have tried to use the filter method but it does not seem to be working as I would have thought from the documentation.


In the end, what I want to do is, if there is a record i want to use that record, otherwise i was to create a new blank record in the store and then i want to display this in the template.


Let me know if I have not been clear enough in this description.





Aucun commentaire:

Enregistrer un commentaire