Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
Created April 30, 2012 14:25
Show Gist options
  • Select an option

  • Save lancejpollard/2558766 to your computer and use it in GitHub Desktop.

Select an option

Save lancejpollard/2558766 to your computer and use it in GitHub Desktop.
Tower.js Discussion - Tower.Model.create vs. Tower.Model.insert

In Rails, you have this API for creating a model:

User.create

In Tower, we were/are also using that method (as of April 30, 2012):

App.User.create

However, in JavaScript, create is used differently by convention. It is used to instantiate a new object, similar to Ruby's Object.new:

Object.create # plain JavaScript
Ember.Object.create # Ember.js way of instantiating objects

Currently in Tower, since we are integrating Ember.js, we have to alias the Ember.Object.create method, to something like this:

Tower.Model.build
Tower.Model.new # or Tower.Model["new"] in plain JavaScript

While I like the elegance of Tower.Model.new in CoffeeScript, it's not a clean solution in JavaScript.

I propose we just stray from the Rails API here and adhere to the JavaScript conventions, using Tower.Model.create to "construct" a new model.

Then the question is, what do we call the method for "inserting" a model to the database (formerly .create)? How about just .insert.

App.User.insert(email: 'example@localhost.com')

What are your thoughts?

@edubkendo
Copy link

.append ? Or does that get too confusing when dealing with client-side code because of appending things to the DOM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment