Mean.io - Best practice to extend User model

十年热恋 提交于 2019-12-08 07:44:29

问题


Mean.io comes with a built in user model within the user package. What is the best practice for extending that user model if I want to attach additional data to it?

My experience with Django had me creating a "profile" that had a foreign key pointing towards the user object it belonged to. I like this approach because I don't touch the user package that way. But is this a best practice? If this is, how can I ensure the creation of a profile doc at the creation of a user doc? If not, what is?


回答1:


I'm not sure qm69's solution would be the best for future compatibility with mean. In the mean.io documentation http://learn.mean.io/ it states the developer shouldn't alter any core packages, including the user package.

The mean.io pattern is to implement any and all extensions as a custom package. And override default views using the $viewPathProvider.override method.

Secondly the User package is fundamentally a security/authentication feature and not a profile implementation which regularly receives updates. Altering this will most likely break future fixes and risk introducing security bugs.

My advice would be to implement a profile using means package system and add a service dependency for the User service. I've done this in previous projects and it works well.

To implement a profile package, follow the below steps:

1) Create a custom package called profile using mean package profile.

2) Implement model/view/control for all profile requirements in the custom package. DONT ALTER ANYTHING IN THE USER package.

2) Use dependency injection to include the Global service service. This will give you access to Global.user data so you most likely don't even need to use the User services.

3) Override any User views using the $override method mentioned in the above doco.

Hope this helps ;)



来源:https://stackoverflow.com/questions/28450348/mean-io-best-practice-to-extend-user-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!