vendredi 9 septembre 2016

Ember findBelongsTo

How to use findBelongsto? So my notes model is related to a contact model (1- many relationship where contact is on the LHS). I need to get all of notes data based on the contact ID. I am fetching this data from a 3rd party API where the related data is fetched in this format: some_url/Contacts/:contactID/link/notes I need to fetch the notes data in the model hook. Can I do it with findBelongsTo like this: findBelongsTo('contact', contactID, 'notes')?

contact model:

import DS from 'ember-data';

export default DS.Model.extend({
  assigned_user_name: DS.attr('string'),
  password_c: DS.attr('string'),
  account_name: DS.attr('string'),
  department: DS.attr('string'),
  description: DS.attr('string'),
  phone_work: DS.attr('string'),
  primary_address_street: DS.attr('string'),
  primary_address_city: DS.attr('string'),
  primary_address_state: DS.attr('string'),
  primary_address_country: DS.attr('string'),
  twitter: DS.attr('string'),

  notes: DS.hasMany('note')
});

note model:

import DS from 'ember-data';

export default DS.Model.extend({
    contact: DS.belongsTo('contact'),
    name: DS.attr('string'),
    description: DS.attr('string')
});




Aucun commentaire:

Enregistrer un commentaire