An issue with data and routes in Ember - ember.js

I am new to Ember.js and I have an issue I can't understand.
When I directly go to index.html#/subjects/1, I have the following data loaded:
subject (1):
Id: 1 - Title: My subject
message (3):
Id: 1 - Html content: undefined - Creation date: undefined
Id: 2 - Html content: undefined - Creation date: undefined
Id: 3 - Html content: undefined - Creation date: undefined
user (2):
Id: 1 - Name: undefined - Email: undefined - ...
Id: 2 - Name: undefined - Email: undefined - ...
Id: 3 - Name: undefined - Email: undefined - ...
And I also have an error (Uncaught TypeError: Cannot read property 'get' of null) on the following line :
return (this.get('sender').get('id') == 1);
But when I go on a page that loads all my fixture data and then go to index.html#/subjects/1, everything works fine.
To help you, this is my app.js file of Ember:
App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter;
App.Router.map(function() {
// ...
this.resource('subjects', function () {
this.resource('subject', {path: ':subject_id'});
});
});
// Some routes ...
App.SubjectRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('subject', params.subject_id);
}
});
// Some controllers ...
App.Subject = DS.Model.extend({
title: DS.attr('string'),
messages: DS.hasMany('message', { async: true }),
users: DS.hasMany('user', { async: true }),
messagesCount: function () {
return this.get('messages.length');
}.property('messages'),
unreadMessagesCount: function () {
return Math.floor(this.get('messages.length')/2);
}.property('messages'),
callsCount: function () {
return Math.floor((Math.random() * this.get('messages.length')));
}.property('messages'),
textListOfUsers: function () {
var res = '';
var users = this.get('users').toArray();
test = this.get('users');
for (i = 0; i < users.length; i++) {
var name = users[i].get('name');
res = res.concat(users[i].get('name'), ' & ');
};
res = res.substring(0, res.length-3);
return res;
}.property('users.#each.name'),
textListOfOtherUsers: function () {
var res = '';
var users = this.get('users').toArray();
test = this.get('users');
for (i = 0; i < users.length; i++) {
var name = users[i].get('name');
if (users[i].get('id') != 1)
res = res.concat(users[i].get('name'), ' & ');
};
res = res.substring(0, res.length-3);
return res;
}.property('users.#each.name')
});
App.Message = DS.Model.extend({
htmlContent: DS.attr('string'),
creationDate: DS.attr('string'),
subject: DS.belongsTo('subject'),
sender: DS.belongsTo('user'),
isFromConnectedUser: function () {
return (this.get('sender').get('id') == 1);
}.property('sender.id') // NOTE: Not sure about the syntax
});
App.User = DS.Model.extend({
name : DS.attr(),
email : DS.attr(),
bio : DS.attr(),
avatarUrl : DS.attr(),
creationDate: DS.attr(),
subjects: DS.hasMany('subject', { async: true }),
messages: DS.hasMany('message', { async: true })
});
App.Subject.FIXTURES = [{
id: 1,
title: 'My subject',
messages: [ 1,2,3 ],
users: [1,2]
}, {
id: 2,
title: 'Hello world',
messages: [ 4 ],
users: [1,2]
// Other data...
}];
App.Message.FIXTURES = [{
id: 1,
htmlContent: 'Message 1',
creationDate: '2015-06-16',
subject: 1,
sender: 1
}, {
id: 2,
htmlContent: 'Message 2',
creationDate: '2015-06-16',
subject: 1,
sender: 2
// Other data...
}];
App.User.FIXTURES = [{
id: 1,
name: 'Alice Bernard',
email: 'alice#bernard.com',
bio: 'Lorem ispum dolor sit amet in voluptate fugiat nulla pariatur.',
avatarUrl: 'images/default-user-image.png',
creationDate: '2015-06-16'
}, {
id: 2,
name: 'John Doe',
email: 'john#doe.com',
bio: 'Lorem ispum dolor sit amet in voluptate fugiat nulla pariatur.',
avatarUrl: 'images/default-user-image.png',
creationDate: '2015-06-16'
// Other data...
}];
Thank you for your help.

Related

how to manage multiple checkboxes in ember?

I'm still trying to figure out how ember works and I want to have more info on managing multiple checkboxes in ember..
here's what I tried to do: http://jsbin.com/datojebu/2/edit
as you can see all checkboxes get selected and the checked function doesn't get called
what's the correct way of doing this?
Check this now. http://jsbin.com/datojebu/3/edit
{{#each genre in genres}}
{{input type="checkbox" name=genre.id checked=genre.isChecked}} {{genre.nom}}
{{/each}}
you have to add genre.isChecked else same isChecked will be binded to all checkboxes.
BTW if you want to have controller for each item, you can add ItemController in the array controller. Here is another example.
/* controllers */
App.AnimesController = Ember.ArrayController.extend({
itemController: 'anime'
});
Okay further to your additional questions, I've basically finished your app for you:
http://jsbin.com/datojebu/11/edit
App = Ember.Application.create();
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: '/api',
namespace: 'fr'
});
/* router */
App.Router.map(function() {
this.resource('animes');
});
App.AnimesRoute = Ember.Route.extend({
model: function() {
return this.store.find('anime');
},
setupController: function(controller, model) {
this._super();
this.store.find('genre').then(function(genres) {
controller.set('genres', genres);
});
controller.set('model', model);
}
});
/* models */
var model = DS.Model,
attr = DS.attr,
hasMany = DS.hasMany;
App.Genre = model.extend({
animes: hasMany('anime', {async: true}),
nom: attr('string')
});
App.Anime = model.extend({
nom: attr('string'),
parution: attr('number'),
synopsis: attr('string'),
likes: attr('number'),
auteur: attr('string'),
genres: hasMany('genre', {async: true})
});
/* controllers */
App.AnimesController = Em.ArrayController.extend({
genres: Em.A([]),
selectedGenreIds: Em.A([]), // a set of ids
selectedGenres: function() {
var genres = this.get('genres'),
selectedGenreIds = this.get('selectedGenreIds');
return genres.filter(function(genre) {
return selectedGenreIds.contains(genre.get('id'));
});
}.property('selectedGenreIds.#each', 'genres.#each'),
selectedAnimes: function() {
var allAnimes = this.get('model'),
selectedGenres = this.get('selectedGenres'),
filteredAnimes;
// for an anime to be shown, it has to have at
// least one of its genres selected
filteredAnimes = allAnimes.filter(function(anime) {
return anime.get('genres').any(function(animeGenre) {
return selectedGenres.contains(animeGenre);
});
});
return filteredAnimes;
}.property('model.#each', 'selectedGenres.#each', 'genres.#each')
});
App.GenreController = Em.ObjectController.extend({
needs: ['animes'],
isChecked: function(key, value) {
if(arguments.length > 1) {
// setter
var selectedGenreIds = this.get('controllers.animes.selectedGenreIds'),
thisId = this.get('id');
if(!selectedGenreIds.contains(thisId) && value) {
selectedGenreIds.addObject(thisId);
} else {
selectedGenreIds.removeObject(thisId);
}
}
// always return the value for the getter and the setter
return value;
}.property('controllers.animes.selectedGenreIds')
});
/* mockjax */
var animes = [
{
id: 1,
nom: 'Blah',
parution: 2014,
genres: [1, 3],
synopsis: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, eveniet, ab pariatur omnis dolor sunt alias atque voluptate neque reiciendis maiores impedit quibusdam perferendis optio ratione expedita adipisci et. Cupiditate!',
likes: 206,
auteur: 'Moi :p'
}
],
genres = [
{
id: 1,
nom: 'action',
animes: []
},
{
id: 2,
nom: 'magie',
animes: [1]
},
{
id: 3,
nom: 'amour et amitier',
animes: []
},
{
id: 4,
nom: 'aventures',
animes: [1]
}
];
$.mockjax({
url: '/api/fr/animes',
responseTime: 750,
responseText: {
'animes': animes
}
});
$.mockjax({
url: '/api/fr/genres',
responseTime: 750,
responseText: {
'genres': genres
}
});
You need to do as CodeJack said...
Once you've done that, you use bindings to "know" which one is checked. That is to say you don't need to know it yourself, you just need to bind the correct values to the right spot.
Anyway, this jsbin should alleviate your issues... notice the console gets set with the value and triggered at the correct tiems/places.
http://jsbin.com/datojebu/6/edit
App = Ember.Application.create();
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: '/api',
namespace: 'fr'
});
/* router */
App.Router.map(function() {
this.resource('animes');
});
App.AnimesRoute = Ember.Route.extend({
model: function() {
return this.store.find('anime');
},
setupController: function(controller, model) {
this._super(controller, model);
this.store.find('genre').then(function(genres){
controller.set('genres', genres);
});
}
});
/* models */
var model = DS.Model,
attr = DS.attr,
hasMany = DS.hasMany;
App.Genre = model.extend({
animes: hasMany('anime', {async: true}),
nom: attr('string')
});
App.Anime = model.extend({
nom: attr('string'),
parution: attr('number'),
synopsis: attr('string'),
likes: attr('number'),
auteur: attr('string'),
genres: hasMany('genre', {async: true})
});
/* controllers */
App.GenreController = Em.ObjectController.extend({
isChecked: function(key, value) {
if(arguments.length > 1) {
// setter
console.log('huzzah' + this.get('id') + ' val: ' + value);
}
// always return the value for the getter and the setter
return this.get('model.isChecked');
}.property(),
actions: {
click: function() {
console.log("hi");
}
}
});
/* mockjax */
var animes = [
{
id: 1,
nom: 'Blah',
parution: 2014,
genres: [1, 3],
synopsis: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, eveniet, ab pariatur omnis dolor sunt alias atque voluptate neque reiciendis maiores impedit quibusdam perferendis optio ratione expedita adipisci et. Cupiditate!',
likes: 206,
auteur: 'Moi :p'
}
],
genres = [
{
id: 1,
nom: 'action',
animes: []
},
{
id: 2,
nom: 'magie',
animes: [1]
},
{
id: 3,
nom: 'amour et amitier',
animes: []
},
{
id: 4,
nom: 'aventures',
animes: [1]
}
];
$.mockjax({
url: '/api/fr/animes',
responseTime: 750,
responseText: {
'animes': animes
}
});
$.mockjax({
url: '/api/fr/genres',
responseTime: 750,
responseText: {
'genres': genres
}
});

Trying To Do A Simple Add Item To FIXTURE

I have a simple fixture:
App.User.FIXTURES = [
{ userid: 1, name: 'George', email: 'george#gmail.com', bio: 'Lorem Ipsum', created: 'Jan 5, 2015' },
{ userid: 2, name: 'Tom', email: 'tom#hotmail.com', bio: 'Lorem Ipsum 2', created: 'Jan 15, 2015' },
{ userid: 3, name: 'Mary', email: 'mary#aol.com', bio: 'Lorem Ipsum 3', created: 'Jan 25, 2015' }
];
And I have a simple submit: (snippet)
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
App.User.createRecord({ id: 4, userid: 4, name: 'Created person', email: 'sdh', bio: 'my bio', created: '6543456' });
I THINK this is right as I'm not getting an error on createRecord anymore, but now I'm getting an error, any ideas? One more step I'm missing just to shove something into a fixture?
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
Kingpin2k is correct in that calling createRecord on the UserModel itself is an older way of using Ember Data. If you're using the latest version you should call createRecord from the store object.
Here's what it should look like:
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
//Create a new user
var user = this.store.createRecord('user',{
id: 4,
userid: 4,
name: 'Created person',
email: 'sdh',
bio: 'my bio',
created: '6543456'
});
// Saves the new model, but not needed if you're just using FIXTURES
// Making the call shouldn't throw any errors though and is used in the Guide
user.save();
// Now you can find your record in the store
this.store.find('user', 4).then(function(user){
console.info(user);
});
}
}
});
This was tested on:
DEBUG: -------------------------------
DEBUG: Ember : 1.6.0-beta.1+canary.24b19e51
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 2.0.2
DEBUG: -------------------------------
I'd recommend reviewing the "Creating a New Model Instance" portion of the Ember getting started guide as they cover this topic there:
http://emberjs.com/guides/getting-started/creating-a-new-model/

Performing a nested grouping in Ember.js

I need to perform nested grouping on my model in order to display it.
Here is the desired output I need:
---- Today ----
-- Thread 1
- Activity 1
- Activity 2
-- Thread 2
-- Activity 1
---- Yesterday ----
-- Thread 1
- Activity 1
- Activity 2
-- Thread 2
- Activity 1
I am not able to figure out an optimal way to achieve this. I need help developing a proper controller and view / template.
Here is my bare-minimum app setup with fixtures so that you have more idea about my models.
(function($, Ember) {
'use strict';
var App = Ember.Application.create({
rootElement: '#app-container'
});
App.Store = DS.Store.extend({
revision: 13,
adapter: DS.FixtureAdapter
});
App.Thread = DS.Model.extend({
title: DS.attr('string'),
url: DS.attr('string'),
kind: DS.attr('string'),
lastActivityOn: DS.attr('date'),
activities: DS.hasMany('activity')
});
App.Activity = DS.Model.extend({
kind: DS.attr('string'),
date: DS.attr('date'),
performer: DS.belongdTo('user'),
thread: DS.belongsTo('thread')
});
App.User = DS.Model.extend({
userName: DS.attr('string'),
displayName: DS.attr('string'),
profilePicUrl: DS.attr('string'),
activities: DS.hasMany('activity')
});
App.Thread.FIXTURES = [
{
id: '958173B3-EA1C-4E06-873A-038097A65E2F',
title: 'SE01',
url: '/sites/moon551/se01',
kind: 'Workspace',
lastActivityOn: '2014-03-01 10:46:31.4000000'
},
{
id: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2',
title: 'To Do',
url: '/sites/moon551/se02/lists/todo',
kind: 'List',
lastActivityOn: '2014-02-28 11:46:31.4000000'
},
{
id: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC',
title: 'Design UX',
url: '/sites/moon551/se03/lists/todo/1',
kind: 'ListItem',
lastActivityOn: '2014-02-27 12:46:31.4000000'
}
];
App.Activity.FIXTURES = [
{
id: '37D7CBCD-0299-4203-8BF0-1B2DB676467F',
kind: 'Created',
date: '2014-03-01 10:30:31.4000000',
performer: 1073741823,
thread: '958173B3-EA1C-4E06-873A-038097A65E2F'
},
{
id: 'C378CD09-388C-403C-8558-3A1D6B5DCD97',
kind: 'Updated',
date: '2014-03-01 10:46:31.4000000',
performer: 1073741823,
thread: '958173B3-EA1C-4E06-873A-038097A65E2F'
},
{
id: 'C6B68036-7543-466F-85AF-141DB4874F75',
kind: 'Created',
date: '2014-02-28 11:30:31.4000000',
performer: 1073741823,
thread: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2'
},
{
id: 'C378CD09-388C-403C-8558-3A1D6B5DCD97',
kind: 'Updated',
date: '2014-02-28 11:46:31.4000000',
performer: 1073741823,
thread: '9B45E3F0-13FD-48BE-83ED-F3C096C3BCC2'
},
{
id: 'C064010D-2603-4E28-9DE5-568212F1EFCA',
kind: 'Created',
date: '2014-02-27 12:30:31.4000000',
performer: 1073741823,
thread: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC'
},
{
id: '3C449D67-F231-4DB1-8D4D-AE0C39DB4E5D',
kind: 'Updated',
date: '2014-02-27 12:46:31.4000000',
performer: 1073741823,
thread: '6E6E4EE4-5568-49B3-B9E2-66CD60BA6CAC'
}
];
App.User.FIXTURES = [
{
id: 1073741823,
userName: 'Administrator',
displayName: 'System Account'
}
];
App.IndexController = Ember.ArrayController.extend();
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('activity');
}
});
})(jQuery, Ember);
Here is an actual mock-up:
I'm an emberjs noob so take this answer for what it is. I was in a similar situation where I needed to group posts by dates (Year,Month,Day). I used moment.js to extract the days. Here is how I did it.
I was getting data from the server that looked like this :
{
"idea": [{
"_id": "548c7362b9b39b8305000001",
"newTitle": null,
"body": "test",
"date": "2014-12-13T17:12:02.415Z"
}, {
"_id": "548c785c94e310a905000001",
"newTitle": null,
"body": "this is my awesome idea\n",
"date": "2014-12-13T17:33:16.316Z"
}, {
"_id": "548c786e94e310a905000002",
"newTitle": null,
"body": "this is my awesome \n\nanother awesome idea\n",
"date": "2014-12-13T17:33:34.214Z"
}, {
"_id": "548cafb494e310a905000003",
"newTitle": null,
"body": "mii\n",
"date": "2014-12-13T21:29:24.934Z"
}]
}
My Emberjs Route looked like this
saveIdea.IdeasRoute = Ember.Route.extend({
model: function () {
return this.store.find('idea',{page:1,skip:1});
}
});
And My Emberjs controller is the following. I'm using moment.js to extract and format the year, month and day of my dates.
saveIdea.IdeasController = Ember.ArrayController.extend({
test : Ember.computed('content', function() {
var results = {}
var result = [];
this.get('content').forEach(function(item){
var date = item.get('date');
var month = moment(date).format('MMMM');
var year = moment(date).format('YYYY');
var day = moment(date).format('DD');
var dayOfWeek = moment(date).format('dddd');
var time = moment(date).format('LT');
var body = item.get('body');
var groupYear = result.findBy('year',year);
if(!groupYear)
{
result.pushObject(Ember.Object.create({
year: year,
months: []
}));
}
var groupMonths = result.findBy('year',year).months.findBy('month',month);
if(!groupMonths)
{
result.findBy('year',year).months.pushObject(Ember.Object.create({
month: month,
days: []
}));
}
var groupDays = result.findBy('year',year).months.findBy('month',month).days.findBy('day',day);
if(!groupDays)
{
result.findBy('year',year).months.findBy('month',month).days.pushObject(Ember.Object.create({
day: day,
ideas: []
}));
}
result.findBy('year',year).months.findBy('month',month).days.findBy('day',day).ideas.pushObject(Ember.Object.create({
idea: body,
time: time,
dayOfWeek :dayOfWeek
}));
});
return result
})
});
Then in my view, I just looped through the contents of the computed test variable.
I'm not sure how efficient this approach is, but it works just fine for me. You can use this approach to perform your nested grouping.

How to update/edit record in emberjs?

I have collected data from fixture and displayed in form of table.
Also,i have added two column one is edit another is delete now i want to edit specific row.
On click of edit i have populated data on modal window with one update button and i want to update changes on click of update.
Here is my code :
Store :
Grid.Store = DS.Store.extend({adapter: 'DS.FixtureAdapter'});
Router:
Grid.Router.map(function () {
this.resource('mainview', { path: '/' });
});
Grid.MainviewRoute = Ember.Route.extend({
model: function () {
return Grid.ModalModel.find();
}
});
Model :
Grid.ModalModel = DS.Model.extend({
fname: DS.attr('string'),
lname: DS.attr('string'),
email: DS.attr('string'),
contactno: DS.attr('string'),
gendertype: DS.attr('boolean'),
contactype: DS.attr('number')
});
Grid.ModalModel.FIXTURES = [
{
id: 1,
fname: "sachin",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
},
{
id: 2,
fname: "amit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
},
{
id: 3,
fname: "namit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
}
];
Controller :
Grid.MainviewController = Ember.ArrayController.extend({
contentChanged: function() {
this.get('content').forEach(function(item){
var serializer = DS.RESTSerializer.create();
var json_data = serializer.serialize(item);
console.log(JSON.stringify(json_data));
});
}.observes('content.#each'),
showmodal: function(){
$('#modal').modal();
},
showeditmodal: function(){
var rowindex_table = 1;
var contactype = 0;
var post = Grid.ModalModel.find(rowindex_table);
var serializer = DS.RESTSerializer.create();
var cont_edit_data = serializer.serialize(post);
console.log(JSON.stringify(cont_edit_data));
this.set('obj_form_edit_data.cont_data.fname', cont_edit_data["fname"]);
this.set('obj_form_edit_data.cont_data.lname', cont_edit_data["lname"]);
this.set('obj_form_edit_data.cont_data.email', cont_edit_data["email"]);
this.set('obj_form_edit_data.cont_data.contactno', cont_edit_data["contactno"]);
if(cont_edit_data["gendertype"] == true){
this.set('male', true);
$(".cssmale").addClass("active");
}else{
this.set('female', true);
$(".cssfemale").addClass("active");
}
$('.selectpicker').val(cont_edit_data['contactype']);
$('.selectpicker').selectpicker('render');
$('#editmodal').modal();
},
isMale: false,
isFemale: false,
obj_form_edit_data : Ember.Object.create({
cont_data:{
fname : "",
lname : "",
email : "",
contactno : "",
gendertype : "",
contactype : 0
}
}),
gendertype: function(){
this.set('isMale', !this.get('isMale'));
},
savecontact: function(){//save data in local storage
var fname = this.obj_form_edit_data.get('cont_data.fname');
var lname = this.obj_form_edit_data.get('cont_data.lname');
var email = this.obj_form_edit_data.get('cont_data.email');
var contactno = this.obj_form_edit_data.get('cont_data.contactno');
var gendertype = ((this.get('isMale') == true) ? true : false);
var contactype = $(".selectpicker").text();
//Clear view first
this.set('obj_form_edit_data.cont_data.fname', '');
this.set('obj_form_edit_data.cont_data.lname', '');
this.set('obj_form_edit_data.cont_data.email', '');
this.set('obj_form_edit_data.cont_data.contactno', '');
this.set('isMale',false);
this.set('isFemale',false);
$('.selectpicker').val('0');
$('.selectpicker').selectpicker('render');
Grid.ModalModel.createRecord({
fname: fname,
lname: lname,
email: email,
contactno: contactno,
gendertype: gendertype,
contactype: contactype
});
this.get('store').commit();
},
updatecontact: function(){
this.get('store').commit();
}
updatecontact is used to update record on click of update button but it is throwing an error
Uncaught TypeError: Object [object Object] has no method 'commit'
Can anyone tell me how to update record in such case?

ember Uncaught Error: assertion failed: Emptying a view in the inBuffer state

I get this assertion when run the code below:
Emptying a view in the inBuffer state is not allowed and should not
happen under normal circumstances. Most likely there is a bug in your
application. This may be due to excessive property change
notifications.
Link to demo:
http://plnkr.co/edit/s3bUw4JFrJvsL690QUMi
var App = Ember.Application.create({
Store: DS.Store.extend({
revision: 4,
adapter: DS.FixtureAdapter.create()
}),
Router: Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: "/",
connectOutlets: function(router){
var person;
person = App.Person.find(657);
person.addObserver("isLoaded", function() {
return router.get('router.applicationController').connectOutlet("things", person.get("things"));
});
}
})
})
}),
ApplicationController: Em.Controller.extend(),
ApplicationView: Em.View.extend({
template: Em.Handlebars.compile("{{outlet}}")
}),
ThingsController: Em.ArrayController.extend({
thingTypes: (function() {
return App.ThingType.find();
}).property()
}),
ThingsView: Em.View.extend({
template: Em.Handlebars.compile([
'{{#each controller.thingTypes}}',
'{{this.name}}',
'{{/each}}',
'{{#each controller.content}}',
'{{this.title}}',
'{{/each}}'].join(""))
}),
//MODELS
Person: DS.Model.extend({
things: DS.hasMany('App.Thing', {
embedded: true
})
}),
Thing: DS.Model.extend({
description: DS.attr('string'),
thingType: DS.belongsTo("App.ThingType", {
embedded: true
}),
title: (function() {
return this.get("thingType.name");
}).property("description")
}),
ThingType: DS.Model.extend({
name: DS.attr("string")
})
});
App.Person.FIXTURES = [
{
id: 657,
things: [
{
id: 1,
description: "Some text",
thing_type: {
id: 1,
name: "type 1"
}
}, {
id: 2,
description: "Some text",
thing_type: {
id: 2,
name: "type 2"
}
}
]
}
];
App.ThingType.FIXTURES = [
{
id: 1,
name: "type 1"
}, {
id: 2,
name: "type 2"
}, {
id: 3,
name: "type 3"
}
];
Why is this happening?
I was having the same error while trying to load a list of dropdown values from fixtures. What resolved it was overriding queryFixtures on the fixture adapter:
App.FixtureAdapter = DS.FixtureAdapter.extend
latency: 200
queryFixtures: (records, query, type) ->
records.filter (record) ->
for key of query
continue unless query.hasOwnProperty(key)
value = query[key]
return false if record[key] isnt value
true
I probably wouldn't have figured it out had I not set the latency first. Then the error was a bit more descriptive.
a bit late I guess... but I got it to work here:
http://plnkr.co/edit/hDCT4Qy1h5aE6GjM76qp
Didn't change the logic but where its called
I modified your router like this:
Router: Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: "/",
connectOutlets: function(router) {
var person;
router.set('router.applicationController.currentPerson', App.Person.find(657));
}
})
})
})
And created an ApplicationController:
ApplicationController: Em.Controller.extend({
currentPerson: null,
currentPersonLoaded: function() {
this.connectOutlet("things", this.get("currentPerson.things"));
}.observes("currentPerson.isLoaded"),
})
I dont know if this is the output you wished but the bug vanished!