-
Notifications
You must be signed in to change notification settings - Fork 77
Add createInstance
for resources with models
#93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So: var user = DS.createInstance('user', attrs); as sugar for: var user = new DS.definitions.user[DS.definitions.user.class](attrs); |
👍 exactly |
I like it. |
Hmmm, in trying to upgrade I ran into a snag with this solution. I have a function that takes a definition name, but sometimes that name is the plural form of the resource name (ie companies vs company) so what I do is attempt to get the definition from Adding Thanks for letting me talk through this... I think I have a good solution, but it may have been nice to have |
Just realized this is in version 0.10.1, and there's no tag for that yet. So I can't use it quite yet. But that's ok because it allows you to make this change easier (if that's something you want to do). What do you think? |
This was my original proposal, but I can add a method on the resource definition that wraps the var User = DS.defineResource({ name: 'user', ... });
User.find(5).then(...); // Same as DS.find('user', 5)
User.findAll({...}).then(...); // Same as DS.findAll('user', {...})
User.get(5); // Same as DS.get('user', 5)
User.filter({...}); // Same as DS.filter('user', {...})
User.createInstance({...}); // Same as DS.createInstance('user', {...}) |
Yeah, I didn't realize that your proposal wouldn't work with how I implemented it. But I got around it pretty easily. That solution actually sounds amazing. I think it would make things easier to work with. |
Available as of 0.10.1. |
I have this code:
This allows me to do this:
Seems like this would be a common use case. Would be nice if it were baked in. What do you think?
The text was updated successfully, but these errors were encountered: