createRecord using this.get('model') throws an error


#1

Following the example listed here:

An In-Depth Introduction To Ember.js

I’m getting an error whenever I create new records using this.get(‘model’) rather than mapping out each key value pair.

The error is:


Assertion failed: Cannot clone an Ember.Object that does not implement Ember.Copyable

Any thoughts on what could be the cause here? I love the idea of using this.get(‘model’) as it seems pretty elegant in crud scenarios. If I can just extract the record data that would also be splendid.

UsersCreateController = Em.ObjectController.extend

  actions:

    save: ->
      self = @
      user = @get 'model'
      user.set 'creationDate', new Date()
      newUser = @store.createRecord 'user', user

      newUser
        .save()
        .then (model)->
          self.transitionToRoute 'user', newUser

`export default UsersCreateController`

#2

Turns out this is a non-issue if you simply set the model to createRecord initially as per the TRANSITION.md

Since the model for this route is set to a new createRecord, this can be ommitted completely resulting in:

UsersCreateController = Em.ObjectController.extend

  actions:

  save: ->
    self = @
    user = @get 'model'
    user.set 'creationDate', new Date()

    user
      .save()
      .then (model)->
        self.transitionToRoute 'user', user

`export default UsersCreateController`

#3

Thank you for posting the solution.

Worked great for me too :wink: