Hello, I have ben making some website.
I just 2 route contact
and notes
I have rails api below.
api_v1_contact_notes GET /api/v1/contacts/:contact_id/notes(.:format) api/v1/notes#index
POST /api/v1/contacts/:contact_id/notes(.:format) api/v1/notes#create
api_v1_contact_note GET /api/v1/contacts/:contact_id/notes/:id(.:format) api/v1/notes#show
PATCH /api/v1/contacts/:contact_id/notes/:id(.:format) api/v1/notes#update
PUT /api/v1/contacts/:contact_id/notes/:id(.:format) api/v1/notes#update
DELETE /api/v1/contacts/:contact_id/notes/:id(.:format) api/v1/notes#destroy
api_v1_contacts GET /api/v1/contacts(.:format) api/v1/contacts#index
POST /api/v1/contacts(.:format) api/v1/contacts#create
api_v1_contact GET /api/v1/contacts/:id(.:format) api/v1/contacts#show
PATCH /api/v1/contacts/:id(.:format) api/v1/contacts#update
PUT /api/v1/contacts/:id(.:format) api/v1/contacts#update
DELETE /api/v1/contacts/:id(.:format) api/v1/contacts#destroy
Accessing api is success fully.
First I create one route contact and model
model Contact
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
email: DS.attr('string'),
description: DS.attr('string'),
notes: DS.hasMany('note', {async: true})
});
model Note
import DS from 'ember-data';
export default DS.Model.extend({
content: DS.attr('string'),
contact: DS.belongsTo('contact', {async: true})
});
just I add this.store.findAll('contact');
for access all of contact.
so I represent inside one of contact.
contacts/show
route is contacts/:contact_id
Problem is here.
I want to access backend api api/v1/contacts/1/notes
that I created that before I use.
I tried get notes of contact id ‘1’
my contacts/show.js I get contact object have id 1
var contact = this.store.findRecord('contact', params.contact_id);
contact.notes.length
is 0 but I access http://localhost:3000/api/v1/contacts/1/notes return 3 notes.
how I get notes inside contact?