Hi all – fairly new to Meteor here.
I’ve spent a lot of time reading articles and looking over packages to figure out the best way to handle something like this…
Basically, my app has accounts-facebook exclusively for user auth, and instead of allowing client side modification to Meteor.users, I created a UserProfile collection. The goal of it is to allow the user to edit their userprofiles
doc in the database, but Meteor.users
will never be touched.
When a user is created, I’m calling a hook from matb33:collection-hooks:
Meteor.users.after.insert(function(userId, doc) { UserProfile.insert({ userProfileId: doc._id, firstName: doc.firstName, lastName: doc.lastName, email: doc.email, userGender: doc.gender, }); console.log("Success. Created UserProfile."); });
The concept I was going after was using userProfileId
and Meteor.users._id
to define the relationship – I haven’t been able to figure out how to get the client side to edit the UserProfile yet though. I should also note it’s actually working really well to build a userProfile automatically from the defined schema – I’m using Accounts.onCreateUser()
to move these things from user.services.facebook.*
out of nesting and then calling the hook.
Few questions about this:
1.) Is this the best way to make a relationship between Users and other collections (like my userprofiles
collection, or is there a general practice that I can’t seem to find?
2.) Does anyone have any examples or public repo’s using both aldeed:simple-schema
and emmerge:graviton
? I understand ORM’s are somewhat debatable with Meteor, but I’d love to see a super easy way to build relationships and how everyone else out there handles this.
Thanks again – lmk if I’m not being clear enough in my example. I would really love to know the best practices involved here and what the publications might look like…
-Ryan
EDIT:
So I figured out the secure means of publishing userprofiles
, courtesy of Meteorchef’s guide here:
var user = this.userId,
profileId = UserProfile.find({ "userProfileId" : user });
if (profileId){
return profileId;
}
return this.ready();
});```
If any other newbs need to understand the concepts of pub/sub and document association, highly recommend reading that. And definitely read Josh Owen's security series:
[Meteor Security 101](http://joshowens.me/meteor-security-101/)
[Meteor Security 201](http://joshowens.me/meteor-security-201/)
Still wondering how collection associations are best handled and how they're in practice though! :slight_smile:
-Ryan