     equal product2.get('store_id'), record.id
 
     storedJSON = @storeAdapter.storage["stores#{record.id}"]
-    productsJSON = record.get('products').toJSON().map (product) ->
-      # Set.toJSON doesn't apply toJSON on its contents
-      productJSON = product.toJSON()
-      delete productJSON.store
-      productJSON
-    deepEqual storedJSON.products, productsJSON
-
+    deepEqual storedJSON.products, 
+      [{name: "Gizmo", store_id: record.id},
+       {name: "Gadget", store_id: record.id}]
     QUnit.start()
 
 asyncTest "hasMany associations are saved via the child model", 2, ->

    class @App.Product extends Batman.Model
      @encode 'id', 'name'
      @belongsTo 'store'

    @productAdapter = new AsyncTestStorageAdapter @App.Product
    @productAdapter.storage = 
      'products1': {name: "Product One", id: 1, store_id: 1}
      'products2': {name: "Product One", id: 1, store: {id:2, name:"JSON Store"}}
    @App.Product.persist @productAdapter

    @App.run()

asyncTest "should work with model classes that haven't been loaded yet", ->
  class @App.Blog extends Batman.Model
    @encode 'id', 'name'
    @hasOne 'customer'
  blogAdapter = new AsyncTestStorageAdapter @App.Blog
  blogAdapter.storage =
    'blogs1': {name: "Blog One", id: 1}
  @App.Blog.persist blogAdapter

  setTimeout (=>
    class @App.Customer extends Batman.Model
      @encode 'id', 'name'
    customerAdapter = new AsyncTestStorageAdapter @App.Customer
    customerAdapter.storage =
      'customer1': {name: "Customer One", id: 1, blog_id: 1}
    @App.Customer.persist customerAdapter

    @App.Blog.find 1, (err, blog) =>
      customer = blog.get 'customer'
      ok customer instanceof @App.Customer
      equal customer.get('id'), 1
      equal customer.get('name'), 'Customer One'
      QUnit.start()
  ), ASYNC_TEST_DELAY

asyncTest "belongsTo associations are loaded via ID", 2, ->
  @App.Product.find 1, (err, product) =>
    store = product.get 'store'
    ok store instanceof @App.Store
    equal store.id, 1
    QUnit.start()

asyncTest "belongsTo yields the related model when toJSON is called", 1, ->
  @App.Product.find 1, (err, product) =>
    productJSON = product.toJSON()
    storeJSON = product.get('store').toJSON()

    # store will encode its product
    delete storeJSON.product

    deepEqual productJSON.store, storeJSON
    QUnit.start()

asyncTest "hasOne yields the related model when toJSON is called", 1, ->
  @App.Store.find 1, (err, store) =>
    storeJSON = store.toJSON()
    productJSON = store.get('product').toJSON()
    # store will encode its product
    delete productJSON.store

    deepEqual storeJSON.product, productJSON
    QUnit.start()

asyncTest "belongsTo associations are saved", 5, ->

{TestStorageAdapter, AsyncTestStorageAdapter} = if typeof require isnt 'undefined' then require './model_helper' else window
helpers = if typeof require is 'undefined' then window.viewHelpers else require '../view/view_helper'

QUnit.module "belongsTo Associations"
  setup: ->
    class @App extends Batman.App
    # Batman.currentApp exists under node and causes the adapters to explode
    Batman.currentApp = undefined

    class @App.Store extends Batman.Model
      @encode 'id', 'name'
    @storeAdapter = new AsyncTestStorageAdapter @App.Store
    @storeAdapter.storage =
      'stores1': {name: "Store One", id: 1}
