Open vikas-ukani opened 5 years ago
@vikas-ukani try
const class User extends Model {
contacts() {
return this.hasMany('App/Models/Contact')
}
}
const class Contact extends Model {
static get objectIds () { return ['_id', 'user_id'] }
user() {
return this.belongsTo('App/Models/User')
}
}
and remove contact_ids field
make sure your user_id
field in contacts collection is stored as objectid
@vikas-ukani try
const class User extends Model { contacts() { return this.hasMany('App/Models/Contact') } } const class Contact extends Model { static get objectIds () { return ['_id', 'user_id'] } user() { return this.belongsTo('App/Models/User') } }
and remove contact_ids field make sure your
user_id
field in contacts collection is stored asobjectid
I did this but it doesn't work 🙁
In my case, hasMany relation not working database like
Users table
Contact Table
And, I'm applying relation to USERS model
User.js // model
And, The final result is // OUTPUT
When, I applying has many relations it doesn't show contacts list in an array