should a computed property be declared in a model or controller?
ember-data, ember.js
Solution
In this case I think the model is the right place for the computed property because it only makes sense if you have the firstname and lastname attributes.
You can still put computed properties on the controller when it makes sense, but I imagine a property like "fullName" could be used in more than one place across your application (and having this in the controller would force you to duplicate the effort across different parts of the app)
Problem
Having the following User model: ``` Sks.User = DS.Model.extend firstName: DS.attr("string") lastName: DS.attr("string") ``` where should the 'fullName' computed property be declared? ``` fullName: Ember.computed(-> firstName = @get("firstName") lastName = @get("lastName") firstName = "" if firstName is `undefined` lastName = "" if lastName is `undefined` lastName + " " + firstName ).property("firstName", "lastName") ``` Should it be in 'UsersController' or directly in the model? The Ember documentation says that fields used only across session, should be written in controllers. But the problem is I couldn't access 'fullName' in the Index template: ``` Sks.IndexController = Ember.Controller.extend needs: ['users'] ``` Here, 'fullName' was inaccessible (declared in the controller) ``` {{#each user in controllers.users}} <li>{{user.fullName}}</li> {{/each}} ``` But it is when it is in the model.