0
votes

I have an array of objects from my controller. I can display the properties but the linkTo object is not being set

Im also using ember-model not ember-data

Msmapp.ClassroomsRoute = Ember.Route.extend({
  model: function() {
    return Msmapp.Classroom.findAll(); //Ember.Model
  }
});


Msmapp.Classroom = Msmapp.Model.extend({
  classroom_id: Ember.attr('number'),
  classroom_name: Ember.attr('string'),
  teacher_id: Ember.attr('number'),
  grade: Ember.attr('number'),
  students: Ember.attr('string'),
  assignments: Ember.attr('string'),

  classroomStudents: function () {
    var studentObjects = []
    this.get('students').forEach(function(student) {
      studentObjects.push(Msmapp.Student.create(student));
    });
    return studentObjects;
  }.property('students')

});

Msmapp.Classroom.reopenClass({
  collectionKey: "classrooms",
  url: '/classrooms'
});


{{#each classroom in controller }}
  <li class="item">
    {{#linkTo 'classroom' classroom }}{{ classroom.classroom_name }}{{/linkTo}}
  </li>
{{/each}}

The classroom.classroom_name work just fine. I have even changed it to a computed property.

But the link is not setting the model. Its a nested route.

im getting /classrooms/undefined

The odd thing is when i click the link, it populates the classroom model and view.

My route

this.resource('classrooms', function() {
    this.resource('classroom', {path: ':classroom_id'}, function() {
        this.route('new_student');
    });
    this.route('new');
});

note: if i change the :classroom_id to just :id i get back something like this

/classrooms/<Msmapp.Classroom:ember403>

I just switched from ember-data to ember-model so im sure its something trivial im overlooking.

2

2 Answers

1
votes

What is the primary key on your Classroom model? It looks like it is classroom_id instead of id.

Ember.Model assumes a primary key of id, it is currently generating the URL with the id attribute of your classroom model, which is actually undefined because your actual id is classroom_id

You either need to change your data to use id for a primary key (Suggested), or customize Ember-Model to use a different primary key.

0
votes

<Msmapp.Classroom:ember403> is result of model method toString(). I had the same problem and looks like linkTo not looking on rout parameter name. So my solution is

{{#linkTo 'classroom' classroom.classroom_id }}...