Reputation: 3989
In Ember, everything is registered with its type as part of the name. i.e.:
App.FoobarController
App.FoobarView
App.FoobarRoute
Except for Ember-Data models, which are all just called by their root name. i.e.
App.User
App.Post
App.Comment
Why do ember-data models break this pattern instead of being called App.UserModel
, App.PostModel
, App.CommentModel
respectively?
I realize that I can name my models anything I want, but if I go ahead and name my user model App.UserModel
, then all my AJAX requests are sent to /user_models
and expect response JSON with a root element of user_model
/user_models
. I also realize that its possible to register aliases/plurals to make this pattern possible.
But, I can do things like controllerName: 'Foobar'
and templateName: 'Foobar'
, and Ember automagically resolves them to FoobarController
and FoobarTemplate
respectively. I can also define App.FoobarView
and App.FoobarController
and Ember knows that they go together and pairs them up automatically. That said, I would expect the same type of magic to happen for AJAX requests for UserModel
to be rewritten to /users
and to enable fetching via App.store.find( 'User', 123 )
.
Is there a reason this convention has been broken when dealing with models, or is this just an oversight/error/inconsistency with Ember-Data?
Upvotes: 2
Views: 70
Reputation: 19050
Is there a reason this convention has been broken when dealing with models, or is this just an oversight/error/inconsistency with Ember-Data?
I think the convention is not so much broken as it is different that what you expect. In many ways ember is building on conventions used by rails and other MVC frameworks. Typically MVC applications are built around a set of objects that represent the domain model. For example:
User, Post, Comment, etc.
Now for each model there are other framework-specific objects that may be needed, like:
UserController, UserView, UserPresenter, UserMailer, UserTemplate, UserView
So following this convention UserModel would not make sense. I can see an argument that UserModel
would be more clear but would recommend picking your battles. Trying to fight the framework (be it ember, rails, or any other) and use your own naming conventions will result in a lot of extra work. Would recommend going with the defaults unless you've got money to burn or a really good reason.
Upvotes: 2