Ember Data find one

by dmazza

HTML

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="https://github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
<script src="https://github.com/downloads/emberjs/data/ember-data-latest.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember Shoplift" />

<script src="http://code.jquery.com/jquery.min.js"></script>
  
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
<!--<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
  <script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
  <script src="https://github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
  <script src="https://github.com/downloads/emberjs/data/ember-data-latest.js"></script>-->
<meta charset=utf-8 />
<title>The Shoplift</title>
  
  <script type="text/x-handlebars" data-template-name="application">
    {{outlet header}}
    {{outlet sidebar}}
    {{outlet carousel}}
  </script>
  
  
  <script type="text/x-handlebars" data-template-name="items">
      <ul>
      {{collection contentBinding="controller" itemViewClass="Shoplift.ItemView"}}
      </ul>
  </script>
  
  <script type="text/x-handlebars" data-template-name="users">
    {{collection contentBinding="controller" itemViewClass="Shoplift.ProfileView"}}
  </script>
    
  <script type="text/x-handlebars" data-template-name="item">
      Item:
  {{#with view.content}}
        <ul>
            <li>
          {{#with user}}
            {{view Shoplift.UserView}}
          {{/with}}
            </li>
            <li>brand: {{brand}}</li>
           ...

JavaScript

Shoplift = Ember.Application.create();

Shoplift.store = DS.Store.create({
  revision: 4,
  adapter: DS.fixtureAdapter //DS.RESTAdapter.create()
});

Shoplift.Item = DS.Model.extend({
  name: DS.attr('string'),
  relifts: DS.attr('number'),
  brand: DS.attr('string'),
  comment: DS.attr('string'),
  url: DS.attr('string'),
  price: DS.attr('number'),
  photo_file_name: DS.attr('string'),
  user: DS.belongsTo('Shoplift.User')
});

Shoplift.User = DS.Model.extend({
  //id: DS.attr('number'),
  email: DS.attr('string'),
  username: DS.attr('string'),
  fullName: DS.attr('string'),
  description: DS.attr('string'),
  avatarUrlSmall: DS.attr('string'),
  followeeCount: DS.attr('number'),
  followerCount: DS.attr('number'),
  items: DS.hasMany('Shoplift.Item',  { key: 'item_ids' })
});

Shoplift.Item.FIXTURES = [
  {
    id: 1,
    name: "Something 1",
    relifts: "5",
    brand: "Macy's",
    comment: "I love it",
    url: "http://google.com",
    price: "88",
    photo_file_name: "http://davidmazza.net/shoplift/images/product-img.png",
    user_id: 1
  }, 
  { 
    id: 2,
    name: "Something 2",
    relifts: "5",
    brand: "Sears",
    comment: "I love it",
    url: "http://google.com",
    price: "88",
    photo_file_name: "http://davidmazza.net/shoplift/images/product-img.png",
    user_id: 2
  },
  { 
    id: 3,
    name: "Something 3",
    relifts: "5",
    brand: "Walmart",
    comment: "I love it",
    url: "http://google.com",
    price: "88",
    photo_file_name: "http://davidmazza.net/shoplift/images/product-img.png",
    user_id: 1
  },
  { 
    id: 4,
    name: "Something 4",
    relifts: "5",
    brand: "Caldor",
    comment: "I love it",
    url: "http://google.com",
    price: "88",
    photo_file_name: "http://davidmazza.net/shoplift/images/product-img.png",
    user_id: 3
  },
  { 
    id: 5,
    name: "Something 5",
    relifts: "5",
    brand: "Family Dollar",
    comment: "I love it",
    url: "http://google.com",
    price: "88",
   ...