-
Notifications
You must be signed in to change notification settings - Fork 10
Cannot match against 'undefined' or 'null in JsonApiView with Relationships #4
Copy link
Copy link
Open
Description
Hi, i have an User model that has many Contact.
This is my JsonApiViews/User.js file
const JsonApiView = require('adonis-jsonapi/src/JsonApiView')
class User extends JsonApiView {
get attributes() {
return ['first-name', 'last-name', 'email'];
}
contacts() {
return this.hasMany('App/Http/JsonApiViews/Contact');
}
}
module.exports = User
This is my JsonApiViews/Contact.js file
const JsonApiView = require('adonis-jsonapi/src/JsonApiView')
class Contact extends JsonApiView {
get attributes() {
return ['first-name', 'last-name', 'email', 'phone'];
}
user() {
return this.belongsTo('App/Http/JsonApiViews/User');
}
}
module.exports = Contact
In my ContactCotroller.js in the index method i have this:
* index (request, response) {
const contacts = yield Contact.all()
response.jsonApi('Contact', contacts)
}
And i'm getting this error:
{
"error": {
"type": "TypeError",
"message": "Cannot match against 'undefined' or 'null'.",
"file": "node_modules/adonis-jsonapi/src/JsonApiView.js",
"line": 5
}
}
I started getting that when i configured the relationship. When they were not related, everything worked fine. What i am missing?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels