我正在尝试解决此错误 "Cannot destructure property `relatedQuery' " 但没有成功

I'm trying to solve this error "Cannot destructure property `relatedQuery' " but no success

我与 lucid adonis 建立一对多关系,当我尝试获取 A 数据及其特定 B 相关数据(A hasMany B)时,它向我显示此错误:

Cannot destructure property relatedQuery of 'undefined' or 'null'.

我该如何解决这个问题?

通常我一直试图从 A table 获取所有数据但没有成功, 然后我尝试从 B table 获取数据并且 A 数据变空

(我用的是adonisjs)

//model code
class Device extends Model {
    properties () {
        this.hasMany('App/Models/Property');
    } 
}

class Property extends Model {
    devices() {
        return this.belongsTo('App/Models/Device');
    } 
}

// migration code
class DeviceSchema extends Schema {
    up () {
        this.create('devices', (table) => {
            table.increments();
            table.string('nome');
            table.string('photo');
            table.text('descricao');
            table.timestamps();
        });
    }

    down () {
        this.drop('devices');
    }
}

class PropertySchema extends Schema {
    up () {
        this.create('properties', (table) => {
            table.increments();
            table.string('icon');
            table.string('nome', 40);
            table.integer('deviceId')
                .unsigned()
                .notNullable()
                .references('id')
                .inTable('devices')
                .onUpdate('CASCADE')
                .onDelete('CASCADE');
            table.timestamps();
        });
    }

    down () {
        this.drop('properties')
    }
}

// controller code to get data
const Dev = await Device
    .query()
    .limit(4)
    .with('properties')
    .fetch();

console.log(Dev.toJSON())

我需要所有设备数据及其特定 属性 数据。

问题在这里:

 class Device extends Model {
     properties () {
         this.hasMany('App/Models/Property');
     } 
 }

您需要将 'return' 放入关系函数调用中:

    class Device extends Model {
        properties () {
      --->>    return this.hasMany('App/Models/Property');
        } 
    }

A​​donisJs 文档:https://adonisjs.com/docs/4.1/relationships