FacultyCreative / ngActiveResource

Connects business objects and REST web services for Angular.js
255 stars 34 forks source link

Coffeescript Problems #59

Open jkarmel opened 10 years ago

jkarmel commented 10 years ago

Hey guys,

First off, this library is totally awesome and also badly needed in the angular community. I'm incredibly happy to see it!

Secondly, I have the following coffeescript model:

angular.module('models').
factory 'Account', [\
"ActiveResource"
(ActiveResource) ->
  Account = (data) ->
    @number 'id'
    @string 'phone_number'

    @hasMany 'orders'

  Account.inherits ActiveResource.Base
  Account.api.set('/accounts').format 'json'
  Account
]

Part of the code that makes associations work in your library fails because Account.name returns "" instead of "Account". I can use the class keyword to get the right behavior but that won't survive minification. (I think)

Can you guys support a .className property that gets set explicitly?

For reference here is an example using the name property in your code:

function nameOfBelongsToModel(model) {
  if (!model)
    return;
  if (!model.klass && !model.name)
    return;
  if (!model.klass)
    return model.name.camelize();
  return model.klass.name.camelize();
}
jkarmel commented 10 years ago

Oh also, you probably know this but a function's .name property is readonly, so I can't just override that.

briebug commented 10 years ago

I just submitted a pull request that may help you out. IE doesn't support the Function.name property and thus why your code is failing. Take a look at my pull request and see if that doesn't help you out.

Good luck