properties = {} for underscoredAttr, type of schema.attributes attr = underscoredAttr.camelize() if dsTypes[type]? if attr.match(/Id$/) and dsTypes[type] == 'number' # On the serializer side, we serialize belongs_to relationships as # integer _id fields, since AMS doesn't support belongs_to yet, and # has_one sideloads the association, causing infinite recursion. # Because of that, we infer a belongsTo relationship when we see _id # attributes in the schema. assoc = attr.replace(/Id$/, '') properties[assoc] = DS.belongsTo('App.' + assoc.capitalize()) else properties[attr] = DS.attr(dsTypes[type]) else # Ember.required doesn't quite do what we want it to yet, but maybe it # will be fixed. https://github.com/emberjs/ember.js/issues/1299 properties[attr] = Ember.required() for assoc, info of schema.associations assoc = assoc.camelize() if tableName = info?.belongs_to properties[assoc] = DS.belongsTo('App.' + tableName.classify().capitalize()) else if tableName = info?.has_many properties[assoc] = DS.hasMany('App.' + tableName.classify().capitalize()) else if tableName = info?.has_one properties[assoc] = DS.belongsTo('App.' + tableName.classify().capitalize()) # Do validator stuff here, if you so desire App["#{className}Base"] = App.Model.extend properties Thursday, March 28, 13