Reputation: 11
I'm beginner in Sails Js and I can't understand how association's model works. I grow up with relacional method and I can't abstract my thought to understand how I can do this. I only see relations via ID for join tables.
I read Waterline and Sails Js documentation and did exemples... But I can't see how things happen. Furthermore, I wanna save in mongo schema. Like:
// User Model
user_list {
uid,
social:{
facebook:{
uid,
accessToken
}
}
}
Thanks for all, guys.
Upvotes: 1
Views: 50
Reputation: 793
I'm not sur I fully understand your problem but maybe this will give you more clue on how associations work in sails.
As far as I know you cannot nest your object attributes in sails. What you must do, as you would have done in a relational database is create two models.
I understand that you want to build a One-to-One association between your User model and your Social model.
You can do something like this:
uid : {
type : 'integer',
unique : 'true'
},
social : {
model : 'social'
}
type :{
type : 'string',
in : ['facebook', 'twitter', 'other']
}
uid :{
model : 'user',
}
accessToken : {
type : 'string',
required : 'true'
}
Note that by default sails use the documentId as reference and not the uid defined here.
Hope this will help a bit.
Upvotes: 1